r369791 - [Sema] Don't warn on printf('%hd', [char]) (PR41467)

2019-08-23 Thread Nathan Huckleberry via cfe-commits
Author: nathan-huckleberry
Date: Fri Aug 23 11:01:57 2019
New Revision: 369791

URL: http://llvm.org/viewvc/llvm-project?rev=369791=rev
Log:
[Sema] Don't warn on printf('%hd', [char]) (PR41467)

Summary: Link: https://bugs.llvm.org/show_bug.cgi?id=41467

Reviewers: rsmith, nickdesaulniers, aaron.ballman, lebedev.ri

Reviewed By: nickdesaulniers, aaron.ballman, lebedev.ri

Subscribers: lebedev.ri, nickdesaulniers, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/Sema/format-strings-pedantic.c
Modified:
cfe/trunk/lib/AST/FormatString.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/FixIt/format.m
cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp
cfe/trunk/test/Sema/format-strings.c

Modified: cfe/trunk/lib/AST/FormatString.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/FormatString.cpp?rev=369791=369790=369791=diff
==
--- cfe/trunk/lib/AST/FormatString.cpp (original)
+++ cfe/trunk/lib/AST/FormatString.cpp Fri Aug 23 11:01:57 2019
@@ -386,6 +386,8 @@ ArgType::matchesType(ASTContext , Qual
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchPedantic;
 return T == C.UnsignedCharTy || T == C.SignedCharTy ? Match
 : NoMatch;
   case BuiltinType::Short:

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=369791=369790=369791=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Aug 23 11:01:57 2019
@@ -8119,9 +8119,13 @@ CheckPrintfHandler::checkFormatExpr(cons
   // function.
   if (ICE->getType() == S.Context.IntTy ||
   ICE->getType() == S.Context.UnsignedIntTy) {
-// All further checking is done on the subexpression.
-if (AT.matchesType(S.Context, ExprTy))
+// All further checking is done on the subexpression
+const analyze_printf::ArgType::MatchKind ImplicitMatch =
+AT.matchesType(S.Context, ExprTy);
+if (ImplicitMatch == analyze_printf::ArgType::Match)
   return true;
+if (ImplicitMatch == analyze_printf::ArgType::NoMatchPedantic)
+  Pedantic = true;
   }
 }
   } else if (const CharacterLiteral *CL = dyn_cast(E)) {

Modified: cfe/trunk/test/FixIt/format.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/format.m?rev=369791=369790=369791=diff
==
--- cfe/trunk/test/FixIt/format.m (original)
+++ cfe/trunk/test/FixIt/format.m Fri Aug 23 11:01:57 2019
@@ -205,9 +205,7 @@ void test_percent_C() {
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%f"
   // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"(unichar)"
 
-  NSLog(@"%C", (char)0x260300); // expected-warning{{format specifies type 
'unichar' (aka 'unsigned short') but the argument has type 'char'}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
-  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:22}:"(unichar)"
+  NSLog(@"%C", (char)0x260300);
 
   NSLog(@"%C", 'a'); // expected-warning{{format specifies type 'unichar' (aka 
'unsigned short') but the argument has type 'char'}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"

Modified: cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp?rev=369791=369790=369791=diff
==
--- cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp (original)
+++ cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp Fri Aug 23 11:01:57 
2019
@@ -79,10 +79,10 @@ void testChar(CharEnum input) {
   printf("%hhd", input); // no-warning
   printf("%hhd", CharConstant); // no-warning
 
-  // This is not correct but it is safe. We warn because '%hd' shows intent.
-  printf("%hd", input); // expected-warning{{format specifies type 'short' but 
the argument has underlying type 'char'}}
-  printf("%hd", CharConstant); // expected-warning{{format specifies type 
'short'}}
-  
+  // This is not correct, but it is safe. Only warned in pedantic mode because 
'%hd' shows intent.
+  printf("%hd", input);
+  printf("%hd", CharConstant);
+
   // This is not correct but it matches the promotion rules (and is safe).
   printf("%d", input); // no-warning
   printf("%d", CharConstant); // no-warning

Added: cfe/trunk/test/Sema/format-strings-pedantic.c
URL: 

r369414 - [Attr] Support _attribute__ ((fallthrough))

2019-08-20 Thread Nathan Huckleberry via cfe-commits
Author: nathan-huckleberry
Date: Tue Aug 20 10:16:49 2019
New Revision: 369414

URL: http://llvm.org/viewvc/llvm-project?rev=369414=rev
Log:
[Attr] Support _attribute__ ((fallthrough))

Summary: Fixed extraneous matches of non-NullStmt

Reviewers: aaron.ballman, rsmith, efriedma, xbolva00

Reviewed By: aaron.ballman, rsmith, xbolva00

Subscribers: riccibruno, arphaman, ziangwan, ojeda, xbolva00, nickdesaulniers, 
cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/Sema/fallthrough-attr.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/test/SemaCXX/switch-implicit-fallthrough.cpp
cfe/trunk/test/SemaCXX/warn-unused-label-error.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=369414=369413=369414=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Tue Aug 20 10:16:49 2019
@@ -1170,7 +1170,7 @@ def ExtVectorType : Attr {
 
 def FallThrough : StmtAttr {
   let Spellings = [CXX11<"", "fallthrough", 201603>, C2x<"", "fallthrough">,
-   CXX11<"clang", "fallthrough">];
+   CXX11<"clang", "fallthrough">, GCC<"fallthrough">];
 //  let Subjects = [NullStmt];
   let Documentation = [FallthroughDocs];
 }

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=369414=369413=369414=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Aug 20 10:16:49 2019
@@ -2107,12 +2107,13 @@ private:
 
   DeclGroupPtrTy ParseDeclaration(DeclaratorContext Context,
   SourceLocation ,
-  ParsedAttributesWithRange );
-  DeclGroupPtrTy ParseSimpleDeclaration(DeclaratorContext Context,
-SourceLocation ,
-ParsedAttributesWithRange ,
-bool RequireSemi,
-ForRangeInit *FRI = nullptr);
+  ParsedAttributesWithRange ,
+  SourceLocation *DeclSpecStart = nullptr);
+  DeclGroupPtrTy
+  ParseSimpleDeclaration(DeclaratorContext Context, SourceLocation ,
+ ParsedAttributesWithRange , bool RequireSemi,
+ ForRangeInit *FRI = nullptr,
+ SourceLocation *DeclSpecStart = nullptr);
   bool MightBeDeclarator(DeclaratorContext Context);
   DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec , DeclaratorContext Context,
 SourceLocation *DeclEnd = nullptr,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=369414=369413=369414=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Aug 20 10:16:49 2019
@@ -1741,9 +1741,10 @@ void Parser::stripTypeAttributesOffDeclS
 /// [C++11/C11] static_assert-declaration
 /// others... [FIXME]
 ///
-Parser::DeclGroupPtrTy Parser::ParseDeclaration(DeclaratorContext Context,
-SourceLocation ,
-  ParsedAttributesWithRange ) {
+Parser::DeclGroupPtrTy
+Parser::ParseDeclaration(DeclaratorContext Context, SourceLocation ,
+ ParsedAttributesWithRange ,
+ SourceLocation *DeclSpecStart) {
   ParenBraceBracketBalancer BalancerRAIIObj(*this);
   // Must temporarily exit the objective-c container scope for
   // parsing c none objective-c decls.
@@ -1763,8 +1764,8 @@ Parser::DeclGroupPtrTy Parser::ParseDecl
   SourceLocation InlineLoc = ConsumeToken();
   return ParseNamespace(Context, DeclEnd, InlineLoc);
 }
-return ParseSimpleDeclaration(Context, DeclEnd, attrs,
-  true);
+return ParseSimpleDeclaration(Context, DeclEnd, attrs, true, nullptr,
+  DeclSpecStart);
   case tok::kw_namespace:
 ProhibitAttributes(attrs);
 return ParseNamespace(Context, DeclEnd);
@@ -1777,7 +1778,8 @@ Parser::DeclGroupPtrTy Parser::ParseDecl
 SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
 break;
   default:
-return ParseSimpleDeclaration(Context, DeclEnd, attrs, true);
+return ParseSimpleDeclaration(Context, DeclEnd, attrs, true, nullptr,
+   

[clang-tools-extra] r367694 - [clang-tidy] Adding static analyzer check to list of clang-tidy checks

2019-08-02 Thread Nathan Huckleberry via cfe-commits
Author: nathan-huckleberry
Date: Fri Aug  2 10:18:31 2019
New Revision: 367694

URL: http://llvm.org/viewvc/llvm-project?rev=367694=rev
Log:
[clang-tidy] Adding static analyzer check to list of clang-tidy checks

Summary:
Since clang-tidy supports use of the static analyzer there
should be documentation of how to invoke the static analyzer
checks.

Reviewers: JonasToth, aaron.ballman, NoQ, Szelethus

Reviewed By: aaron.ballman

Subscribers: nickdesaulniers, lebedev.ri, jfb, NoQ, Eugene.Zelenko, xazax.hun, 
baloghadamsoftware, a.sidorin, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

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

Added:

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.CallAndMessage.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.DivideZero.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.DynamicTypePropagation.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.NonNullParamChecker.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.NullDereference.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.StackAddressEscape.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.UndefinedBinaryOperatorResult.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.VLASize.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.uninitialized.ArraySubscript.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.uninitialized.Assign.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.uninitialized.Branch.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.uninitialized.CapturedBlockVariable.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-core.uninitialized.UndefReturn.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-cplusplus.InnerPointer.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-cplusplus.Move.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-cplusplus.NewDelete.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-cplusplus.NewDeleteLeaks.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-deadcode.DeadStores.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-nullability.NullPassedToNonnull.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-nullability.NullReturnedFromNonnull.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-nullability.NullableDereferenced.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-nullability.NullablePassedToNonnull.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-nullability.NullableReturnedFromNonnull.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-optin.cplusplus.UninitializedObject.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-optin.cplusplus.VirtualCall.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-optin.mpi.MPI-Checker.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-optin.osx.OSObjectCStyleCast.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-optin.performance.GCDAntipattern.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-optin.performance.Padding.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-optin.portability.UnixAPI.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-osx.API.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-osx.MIG.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-osx.NumberObjectConversion.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-osx.OSObjectRetainCount.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-osx.ObjCProperty.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-osx.SecKeychainAPI.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-osx.cocoa.AtSync.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-osx.cocoa.AutoreleaseWrite.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-osx.cocoa.ClassRelease.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-osx.cocoa.Dealloc.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-osx.cocoa.IncompatibleMethodTypes.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/clang-analyzer-osx.cocoa.Loops.rst


r367134 - [Sema] Fix -Wuninitialized for struct assignment from GNU C statement expression

2019-07-26 Thread Nathan Huckleberry via cfe-commits
Author: nathan-huckleberry
Date: Fri Jul 26 10:29:35 2019
New Revision: 367134

URL: http://llvm.org/viewvc/llvm-project?rev=367134=rev
Log:
[Sema] Fix -Wuninitialized for struct assignment from GNU C statement expression

Summary:
Do not automatically report self references of structs in statement expression
as warnings. Instead wait for uninitialized cfg analysis.
https://bugs.llvm.org/show_bug.cgi?id=42604

Reviewers: aaron.ballman, rsmith, nickdesaulniers

Reviewed By: aaron.ballman, nickdesaulniers

Subscribers: nathanchance, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/Sema/warn-uninitialized-statement-expression.c
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=367134=367133=367134=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jul 26 10:29:35 2019
@@ -11257,9 +11257,12 @@ void Sema::AddInitializerToDecl(Decl *Re
   // Check for self-references within variable initializers.
   // Variables declared within a function/method body (except for references)
   // are handled by a dataflow analysis.
-  if (!VDecl->hasLocalStorage() || VDecl->getType()->isRecordType() ||
-  VDecl->getType()->isReferenceType()) {
-CheckSelfReference(*this, RealDecl, Init, DirectInit);
+  // This is undefined behavior in C++, but valid in C.
+  if (getLangOpts().CPlusPlus) {
+if (!VDecl->hasLocalStorage() || VDecl->getType()->isRecordType() ||
+VDecl->getType()->isReferenceType()) {
+  CheckSelfReference(*this, RealDecl, Init, DirectInit);
+}
   }
 
   // If the type changed, it means we had an incomplete type that was

Added: cfe/trunk/test/Sema/warn-uninitialized-statement-expression.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-uninitialized-statement-expression.c?rev=367134=auto
==
--- cfe/trunk/test/Sema/warn-uninitialized-statement-expression.c (added)
+++ cfe/trunk/test/Sema/warn-uninitialized-statement-expression.c Fri Jul 26 
10:29:35 2019
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -verify %s
+
+void init(int *);
+
+void foo(void) {
+  int i = ({
+init();
+i;
+  });
+}
+
+void foo_bad(void) {
+  int i = ({
+int z = i; // expected-warning{{variable 'i' is uninitialized when used 
within its own initialization}}
+init();
+i;
+  });
+}
+
+struct widget {
+  int x, y;
+};
+void init2(struct widget *);
+
+void bar(void) {
+  struct widget my_widget = ({
+init2(_widget);
+my_widget;
+  });
+  struct widget a = (init2(), a);
+}
+
+void bar_bad(void) {
+  struct widget my_widget = ({
+struct widget z = my_widget; // expected-warning{{variable 'my_widget' is 
uninitialized when used within its own initialization}}
+int x = my_widget.x; //FIXME: There should be an uninitialized 
warning here
+init2(_widget);
+my_widget;
+  });
+}
+
+void baz(void) {
+  struct widget a = ({
+struct widget b = ({
+  b = a; // expected-warning{{variable 'a' is uninitialized when used 
within its own initialization}}
+});
+a;
+  });
+}
+
+void f(void) {
+  struct widget *a = ({
+init2(a); // expected-warning{{variable 'a' is uninitialized when used 
within its own initialization}}
+a;
+  });
+}


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


[clang-tools-extra] r366353 - [clang-tidy] Fix crash on end location inside macro

2019-07-17 Thread Nathan Huckleberry via cfe-commits
Author: nathan-huckleberry
Date: Wed Jul 17 10:22:43 2019
New Revision: 366353

URL: http://llvm.org/viewvc/llvm-project?rev=366353=rev
Log:
[clang-tidy] Fix crash on end location inside macro

Summary:
Lexer::getLocForEndOfToken is defined to return an
invalid location if the given location is inside a macro.
Other checks conditionally warn based off location
validity. Updating this check to do the same.

Reviewers: JonasToth, aaron.ballman, nickdesaulniers

Reviewed By: nickdesaulniers

Subscribers: lebedev.ri, nickdesaulniers, xazax.hun, cfe-commits

Tags: #clang

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

Added:
clang-tools-extra/trunk/test/clang-tidy/bugprone-branch-clone-macro-crash.c
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp?rev=366353=366352=366353=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp Wed Jul 17 
10:22:43 2019
@@ -132,9 +132,12 @@ void BranchCloneCheck::check(const Match
   // We report the first occurence only when we find the second one.
   diag(Branches[i]->getBeginLoc(),
"repeated branch in conditional chain");
-  diag(Lexer::getLocForEndOfToken(Branches[i]->getEndLoc(), 0,
-  *Result.SourceManager, 
getLangOpts()),
-   "end of the original", DiagnosticIDs::Note);
+  SourceLocation End =
+  Lexer::getLocForEndOfToken(Branches[i]->getEndLoc(), 0,
+ *Result.SourceManager, getLangOpts());
+  if (End.isValid()) {
+diag(End, "end of the original", DiagnosticIDs::Note);
+  }
 }
 
 diag(Branches[j]->getBeginLoc(), "clone %0 starts here",
@@ -208,10 +211,12 @@ void BranchCloneCheck::check(const Match
 
 if (EndLoc.isMacroID())
   EndLoc = Context.getSourceManager().getExpansionLoc(EndLoc);
+EndLoc = Lexer::getLocForEndOfToken(EndLoc, 0, *Result.SourceManager,
+getLangOpts());
 
-diag(Lexer::getLocForEndOfToken(EndLoc, 0, *Result.SourceManager,
-getLangOpts()),
- "last of these clones ends here", DiagnosticIDs::Note);
+if (EndLoc.isValid()) {
+  diag(EndLoc, "last of these clones ends here", DiagnosticIDs::Note);
+}
   }
   BeginCurrent = EndCurrent;
 }

Added: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-branch-clone-macro-crash.c
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-branch-clone-macro-crash.c?rev=366353=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-branch-clone-macro-crash.c 
(added)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-branch-clone-macro-crash.c 
Wed Jul 17 10:22:43 2019
@@ -0,0 +1,14 @@
+// RUN: %check_clang_tidy %s bugprone-branch-clone %t
+int x = 0;
+int y = 1;
+#define a(b, c) \
+  typeof(b) d;  \
+  if (b)\
+d = b;  \
+  else if (c)   \
+d = b;
+
+f() {
+  // CHECK-MESSAGES: warning: repeated branch in conditional chain 
[bugprone-branch-clone]
+  a(x, y)
+}


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


r365797 - [Docs] Add standardized header links to analyzer doc

2019-07-11 Thread Nathan Huckleberry via cfe-commits
Author: nathan-huckleberry
Date: Thu Jul 11 10:12:05 2019
New Revision: 365797

URL: http://llvm.org/viewvc/llvm-project?rev=365797=rev
Log:
[Docs] Add standardized header links to analyzer doc

Summary:
Header links should have some standard form so clang tidy
docs can easily reference them. The form is as follows.

Start with the analyzer full name including packages.
Replace all periods with dashes and lowercase everything.

Ex: core.CallAndMessage -> core-callandmessage

Reviewers: JonasToth, aaron.ballman, NoQ, Szelethus

Reviewed By: aaron.ballman, Szelethus

Subscribers: nickdesaulniers, lebedev.ri, baloghadamsoftware, mgrang, 
a.sidorin, Szelethus, jfb, donat.nagy, dkrupp, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/docs/analyzer/checkers.rst

Modified: cfe/trunk/docs/analyzer/checkers.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/analyzer/checkers.rst?rev=365797=365796=365797=diff
==
--- cfe/trunk/docs/analyzer/checkers.rst (original)
+++ cfe/trunk/docs/analyzer/checkers.rst Thu Jul 11 10:12:05 2019
@@ -29,6 +29,8 @@ Models core language features and contai
 null pointer dereference, usage of uninitialized values, etc.
 *These checkers must be always switched on as other checker rely on them.*
 
+.. _core-CallAndMessage:
+
 core.CallAndMessage (C, C++, ObjC)
 ""
  Check for logical errors for function calls and Objective-C message 
expressions (e.g., uninitialized arguments, null function pointers).
@@ -36,6 +38,8 @@ core.CallAndMessage (C, C++, ObjC)
 .. literalinclude:: checkers/callandmessage_example.c
 :language: objc
 
+.. _core-DivideZero:
+
 core.DivideZero (C, C++, ObjC)
 ""
  Check for division by zero.
@@ -43,6 +47,8 @@ core.DivideZero (C, C++, ObjC)
 .. literalinclude:: checkers/dividezero_example.c
 :language: c
 
+.. _core-NonNullParamChecker:
+
 core.NonNullParamChecker (C, C++, ObjC)
 """
 Check for null pointers passed as arguments to a function whose arguments are 
references or marked with the 'nonnull' attribute.
@@ -56,6 +62,8 @@ Check for null pointers passed as argume
  f(p); // warn
  }
 
+.. _core-NullDereference:
+
 core.NullDereference (C, C++, ObjC)
 """
 Check for dereferences of null pointers.
@@ -99,6 +107,8 @@ Check for dereferences of null pointers.
obj->x = 1; // warn
  }
 
+.. _core-StackAddressEscape:
+
 core.StackAddressEscape (C)
 """
 Check that addresses to stack memory do not escape the function.
@@ -123,6 +133,8 @@ Check that addresses to stack memory do
  }
 
 
+.. _core-UndefinedBinaryOperatorResult:
+
 core.UndefinedBinaryOperatorResult (C)
 ""
 Check for undefined results of binary operators.
@@ -134,6 +146,8 @@ Check for undefined results of binary op
int y = x + 1; // warn: left operand is garbage
  }
 
+.. _core-VLASize:
+
 core.VLASize (C)
 
 Check for declarations of Variable Length Arrays of undefined or zero size.
@@ -152,6 +166,8 @@ Check for declarations of Variable Lengt
int vla2[x]; // warn: zero size
  }
 
+.. _core-uninitialized-ArraySubscript:
+
 core.uninitialized.ArraySubscript (C)
 "
 Check for uninitialized values used as array subscripts.
@@ -163,6 +179,8 @@ Check for uninitialized values used as a
int x = a[i]; // warn: array subscript is undefined
  }
 
+.. _core-uninitialized-Assign:
+
 core.uninitialized.Assign (C)
 "
 Check for assigning uninitialized values.
@@ -174,6 +192,8 @@ Check for assigning uninitialized values
x |= 1; // warn: left expression is uninitialized
  }
 
+.. _core-uninitialized-Branch:
+
 core.uninitialized.Branch (C)
 "
 Check for uninitialized values used as branch conditions.
@@ -186,6 +206,8 @@ Check for uninitialized values used as b
  return;
  }
 
+.. _core-uninitialized-CapturedBlockVariable:
+
 core.uninitialized.CapturedBlockVariable (C)
 
 Check for blocks that capture uninitialized values.
@@ -197,6 +219,8 @@ Check for blocks that capture uninitiali
^{ int y = x; }(); // warn
  }
 
+.. _core-uninitialized-UndefReturn:
+
 core.uninitialized.UndefReturn (C)
 ""
 Check for uninitialized values being returned to the caller.
@@ -216,10 +240,14 @@ cplusplus
 
 C++ Checkers.
 
+.. _cplusplus-InnerPointer:
+
 cplusplus.InnerPointer
 ""
 Check for inner pointers of C++ containers used after re/deallocation.
 
+.. _cplusplus-NewDelete:
+
 cplusplus.NewDelete (C++)
 "
 Check for double-free and use-after-free problems. Traces memory managed by 
new/delete.
@@ -227,6 +255,8 @@ Check for double-free and 

r364875 - [analyzer] Support kfree in MallocChecker

2019-07-01 Thread Nathan Huckleberry via cfe-commits
Author: nathan-huckleberry
Date: Mon Jul  1 16:29:10 2019
New Revision: 364875

URL: http://llvm.org/viewvc/llvm-project?rev=364875=rev
Log:
[analyzer] Support kfree in MallocChecker

Summary:
kmalloc is freed with kfree in the linux kernel. kmalloc support was
added in r204832, but kfree was not. Adding kfree fixes incorrectly
detected memory leaks.

Reviewers: NoQ, nickdesaulniers, dcoughlin, Szelethus

Reviewed By: NoQ, Szelethus

Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, 
Szelethus, donat.nagy, dkrupp, Charusso, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/trunk/test/Analysis/kmalloc-linux.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=364875=364874=364875=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Mon Jul  1 16:29:10 
2019
@@ -177,9 +177,10 @@ public:
 II_free(nullptr), II_realloc(nullptr), II_calloc(nullptr),
 II_valloc(nullptr), II_reallocf(nullptr), II_strndup(nullptr),
 II_strdup(nullptr), II_win_strdup(nullptr), II_kmalloc(nullptr),
-II_if_nameindex(nullptr), II_if_freenameindex(nullptr),
-II_wcsdup(nullptr), II_win_wcsdup(nullptr), II_g_malloc(nullptr),
-II_g_malloc0(nullptr), II_g_realloc(nullptr), II_g_try_malloc(nullptr),
+II_kfree(nullptr), II_if_nameindex(nullptr),
+II_if_freenameindex(nullptr), II_wcsdup(nullptr),
+II_win_wcsdup(nullptr), II_g_malloc(nullptr), II_g_malloc0(nullptr),
+II_g_realloc(nullptr), II_g_try_malloc(nullptr),
 II_g_try_malloc0(nullptr), II_g_try_realloc(nullptr),
 II_g_free(nullptr), II_g_memdup(nullptr), II_g_malloc_n(nullptr),
 II_g_malloc0_n(nullptr), II_g_realloc_n(nullptr),
@@ -249,13 +250,13 @@ private:
   mutable IdentifierInfo *II_alloca, *II_win_alloca, *II_malloc, *II_free,
  *II_realloc, *II_calloc, *II_valloc, *II_reallocf,
  *II_strndup, *II_strdup, *II_win_strdup, *II_kmalloc,
- *II_if_nameindex, *II_if_freenameindex, *II_wcsdup,
- *II_win_wcsdup, *II_g_malloc, *II_g_malloc0,
- *II_g_realloc, *II_g_try_malloc, *II_g_try_malloc0,
- *II_g_try_realloc, *II_g_free, *II_g_memdup,
- *II_g_malloc_n, *II_g_malloc0_n, *II_g_realloc_n,
- *II_g_try_malloc_n, *II_g_try_malloc0_n,
- *II_g_try_realloc_n;
+ *II_kfree, *II_if_nameindex, *II_if_freenameindex,
+ *II_wcsdup, *II_win_wcsdup, *II_g_malloc,
+ *II_g_malloc0, *II_g_realloc, *II_g_try_malloc,
+ *II_g_try_malloc0, *II_g_try_realloc, *II_g_free,
+ *II_g_memdup, *II_g_malloc_n, *II_g_malloc0_n,
+ *II_g_realloc_n, *II_g_try_malloc_n,
+ *II_g_try_malloc0_n, *II_g_try_realloc_n;
   mutable Optional KernelZeroFlagVal;
 
   void initIdentifierInfo(ASTContext ) const;
@@ -598,6 +599,7 @@ void MallocChecker::initIdentifierInfo(A
   II_strndup = ("strndup");
   II_wcsdup = ("wcsdup");
   II_kmalloc = ("kmalloc");
+  II_kfree = ("kfree");
   II_if_nameindex = ("if_nameindex");
   II_if_freenameindex = ("if_freenameindex");
 
@@ -657,7 +659,7 @@ bool MallocChecker::isCMemFunction(const
 
 if (Family == AF_Malloc && CheckFree) {
   if (FunI == II_free || FunI == II_realloc || FunI == II_reallocf ||
-  FunI == II_g_free)
+  FunI == II_g_free || FunI == II_kfree)
 return true;
 }
 
@@ -874,7 +876,7 @@ void MallocChecker::checkPostStmt(const
   State = CallocMem(C, CE, State);
   State = ProcessZeroAllocation(C, CE, 0, State);
   State = ProcessZeroAllocation(C, CE, 1, State);
-} else if (FunI == II_free || FunI == II_g_free) {
+} else if (FunI == II_free || FunI == II_g_free || FunI == II_kfree) {
   State = FreeMemAux(C, CE, State, 0, false, ReleasedAllocatedMemory);
 } else if (FunI == II_strdup || FunI == II_win_strdup ||
FunI == II_wcsdup || FunI == II_win_wcsdup) {

Modified: cfe/trunk/test/Analysis/kmalloc-linux.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/kmalloc-linux.c?rev=364875=364874=364875=diff
==
--- cfe/trunk/test/Analysis/kmalloc-linux.c (original)
+++ cfe/trunk/test/Analysis/kmalloc-linux.c Mon Jul  1 16:29:10 2019
@@ -24,7 +24,7 @@ void test_zeroed() {
 t = list[i];
 foo(t);
   }
-  free(list); // 

r364605 - [analyzer] Fix clang-tidy crash on GCCAsmStmt

2019-06-27 Thread Nathan Huckleberry via cfe-commits
Author: nathan-huckleberry
Date: Thu Jun 27 15:46:40 2019
New Revision: 364605

URL: http://llvm.org/viewvc/llvm-project?rev=364605=rev
Log:
[analyzer] Fix clang-tidy crash on GCCAsmStmt

Summary:
Added entry in switch statement to recognize GCCAsmStmt
as a possible block terminator.

Handling to build CFG using GCCAsmStmt was already implemented.

Reviewers: nickdesaulniers, george.karpenkov, NoQ

Reviewed By: nickdesaulniers, NoQ

Subscribers: xbolva00, tmroeder, xazax.hun, baloghadamsoftware, szepet, 
a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, Charusso, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/Analysis/egraph-asm-goto-no-crash.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp?rev=364605=364604=364605=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp Thu Jun 27 15:46:40 2019
@@ -396,6 +396,11 @@ void CoreEngine::HandleBlockExit(const C
   case Stmt::WhileStmtClass:
 HandleBranch(cast(Term)->getCond(), Term, B, Pred);
 return;
+
+  case Stmt::GCCAsmStmtClass:
+assert(cast(Term)->isAsmGoto() && "Encountered GCCAsmStmt 
without labels");
+// TODO: Handle jumping to labels
+return;
 }
   }
 

Added: cfe/trunk/test/Analysis/egraph-asm-goto-no-crash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/egraph-asm-goto-no-crash.cpp?rev=364605=auto
==
--- cfe/trunk/test/Analysis/egraph-asm-goto-no-crash.cpp (added)
+++ cfe/trunk/test/Analysis/egraph-asm-goto-no-crash.cpp Thu Jun 27 15:46:40 
2019
@@ -0,0 +1,26 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
+
+// expected-no-diagnostics
+
+void clang_analyzer_warnIfReached();
+
+void testAsmGoto() {
+  asm goto("xor %0, %0\n je %l[label1]\n jl %l[label2]"
+   : /* no outputs */
+   : /* inputs */
+   : /* clobbers */
+   : label1, label2 /* any labels used */);
+
+  // FIXME: Should be reachable.
+  clang_analyzer_warnIfReached();
+
+  label1:
+  // FIXME: Should be reachable.
+  clang_analyzer_warnIfReached();
+  return;
+
+  label2:
+  // FIXME: Should be reachable.
+  clang_analyzer_warnIfReached();
+  return;
+}


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


r363857 - [AST] Fixed extraneous warnings for binary conditional operator

2019-06-19 Thread Nathan Huckleberry via cfe-commits
Author: nathan-huckleberry
Date: Wed Jun 19 11:37:01 2019
New Revision: 363857

URL: http://llvm.org/viewvc/llvm-project?rev=363857=rev
Log:
[AST] Fixed extraneous warnings for binary conditional operator

Summary:
Binary conditional operator gave warnings where ternary operators
did not. They have been fixed to warn similarly to ternary operators.

Link: https://bugs.llvm.org/show_bug.cgi?id=42239

Reviewers: rsmith, aaron.ballman, nickdesaulniers

Reviewed By: rsmith, nickdesaulniers

Subscribers: srhines, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
Modified:
cfe/trunk/lib/AST/Expr.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=363857=363856=363857=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Jun 19 11:37:01 2019
@@ -2453,12 +2453,13 @@ bool Expr::isUnusedResultAWarning(const
 // If only one of the LHS or RHS is a warning, the operator might
 // be being used for control flow. Only warn if both the LHS and
 // RHS are warnings.
-const ConditionalOperator *Exp = cast(this);
-if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx))
-  return false;
-if (!Exp->getLHS())
-  return true;
-return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+const auto *Exp = cast(this);
+return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) &&
+   Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+  }
+  case BinaryConditionalOperatorClass: {
+const auto *Exp = cast(this);
+return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, 
Ctx);
   }
 
   case MemberExprClass:

Added: cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c?rev=363857=auto
==
--- cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c (added)
+++ cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c Wed Jun 19 
11:37:01 2019
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-value -verify %s
+int main() {
+int a;
+int b;
+a ? : b; //expected-warning{{expression result unused}}
+a ? a : b; //expected-warning{{expression result unused}}
+a ? : ++b;
+a ? a : ++b;
+++a ? : b; //expected-warning{{expression result unused}}
+++a ? a : b; //expected-warning{{expression result unused}}
+++a ? : ++b;
+++a ? a : ++b;
+return 0;
+};
+


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