[llvm-branch-commits] [cfe-branch] r367528 - Merging r367387:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Aug 1 02:03:01 PDT 2019


Author: hans
Date: Thu Aug  1 02:03:00 2019
New Revision: 367528

URL: http://llvm.org/viewvc/llvm-project?rev=367528&view=rev
Log:
Merging r367387:
------------------------------------------------------------------------
r367387 | jdoerfert | 2019-07-31 07:16:38 +0200 (Wed, 31 Jul 2019) | 26 lines

[Fix] Customize warnings for missing built-in types

If we detect a built-in declaration for which we cannot derive a type
matching the pattern in the Builtins.def file, we currently emit a
warning that the respective header is needed. However, this is not
necessarily the behavior we want as it has no connection to the location
of the declaration (which can actually be in the header in question).
Instead, this warning is generated
  - if we could not build the type for the pattern on file (for some
    reason). Here we should make the reason explicit. The actual problem
    is otherwise circumvented as the warning is misleading, see [0] for
    an example.
  - if we could not build the type for the pattern because we do not
    have a type on record, possible since D55483, we should not emit any
    warning. See [1] for a legitimate problem.

This patch address both cases. For the "setjmp" family a new warning is
introduced and for built-ins without type on record, so far
"pthread_create", we do not emit the warning anymore.

Also see: PR40692

[0] https://lkml.org/lkml/2019/1/11/718
[1] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235583

Differential Revision: https://reviews.llvm.org/D58091
------------------------------------------------------------------------

Added:
    cfe/branches/release_90/test/Sema/builtin-setjmp.c
      - copied unchanged from r367387, cfe/trunk/test/Sema/builtin-setjmp.c
Modified:
    cfe/branches/release_90/   (props changed)
    cfe/branches/release_90/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/branches/release_90/lib/Sema/SemaDecl.cpp
    cfe/branches/release_90/test/Analysis/retain-release.m
    cfe/branches/release_90/test/Sema/implicit-builtin-decl.c

Propchange: cfe/branches/release_90/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug  1 02:03:00 2019
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:366429,366448,366457,366474,366480,366483,366511,366670,366694,366699,366878,367008,367039,367055,367103,367134,367301,367305,367323
+/cfe/trunk:366429,366448,366457,366474,366480,366483,366511,366670,366694,366699,366878,367008,367039,367055,367103,367134,367301,367305,367323,367387
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_90/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_90/include/clang/Basic/DiagnosticSemaKinds.td?rev=367528&r1=367527&r2=367528&view=diff
==============================================================================
--- cfe/branches/release_90/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/branches/release_90/include/clang/Basic/DiagnosticSemaKinds.td Thu Aug  1 02:03:00 2019
@@ -598,6 +598,10 @@ def ext_implicit_lib_function_decl : Ext
 def note_include_header_or_declare : Note<
   "include the header <%0> or explicitly provide a declaration for '%1'">;
 def note_previous_builtin_declaration : Note<"%0 is a builtin with type %1">;
+def warn_implicit_decl_no_jmp_buf
+    : Warning<"declaration of built-in function '%0' requires the declaration"
+    " of the 'jmp_buf' type, commonly provided in the header <setjmp.h>.">,
+      InGroup<DiagGroup<"incomplete-setjmp-declaration">>;
 def warn_implicit_decl_requires_sysheader : Warning<
   "declaration of built-in function '%1' requires inclusion of the header <%0>">,
   InGroup<BuiltinRequiresHeader>;

Modified: cfe/branches/release_90/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_90/lib/Sema/SemaDecl.cpp?rev=367528&r1=367527&r2=367528&view=diff
==============================================================================
--- cfe/branches/release_90/lib/Sema/SemaDecl.cpp (original)
+++ cfe/branches/release_90/lib/Sema/SemaDecl.cpp Thu Aug  1 02:03:00 2019
@@ -1984,10 +1984,27 @@ NamedDecl *Sema::LazilyCreateBuiltin(Ide
   ASTContext::GetBuiltinTypeError Error;
   QualType R = Context.GetBuiltinType(ID, Error);
   if (Error) {
-    if (ForRedeclaration)
-      Diag(Loc, diag::warn_implicit_decl_requires_sysheader)
-          << getHeaderName(Context.BuiltinInfo, ID, Error)
+    if (!ForRedeclaration)
+      return nullptr;
+
+    // If we have a builtin without an associated type we should not emit a
+    // warning when we were not able to find a type for it.
+    if (Error == ASTContext::GE_Missing_type)
+      return nullptr;
+
+    // If we could not find a type for setjmp it is because the jmp_buf type was
+    // not defined prior to the setjmp declaration.
+    if (Error == ASTContext::GE_Missing_setjmp) {
+      Diag(Loc, diag::warn_implicit_decl_no_jmp_buf)
           << Context.BuiltinInfo.getName(ID);
+      return nullptr;
+    }
+
+    // Generally, we emit a warning that the declaration requires the
+    // appropriate header.
+    Diag(Loc, diag::warn_implicit_decl_requires_sysheader)
+        << getHeaderName(Context.BuiltinInfo, ID, Error)
+        << Context.BuiltinInfo.getName(ID);
     return nullptr;
   }
 

Modified: cfe/branches/release_90/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_90/test/Analysis/retain-release.m?rev=367528&r1=367527&r2=367528&view=diff
==============================================================================
--- cfe/branches/release_90/test/Analysis/retain-release.m (original)
+++ cfe/branches/release_90/test/Analysis/retain-release.m Thu Aug  1 02:03:00 2019
@@ -2,7 +2,7 @@
 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
 // RUN:     -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
 // RUN:     -analyzer-checker=osx.cocoa.ClassRelease,osx.cocoa.RetainCount\
-// RUN:     -analyzer-checker=debug.ExprInspection -fblocks -verify=expected,C %s\
+// RUN:     -analyzer-checker=debug.ExprInspection -fblocks -verify %s\
 // RUN:     -Wno-objc-root-class -analyzer-output=plist -o %t.objc.plist
 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
 // RUN:     -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
@@ -1231,7 +1231,7 @@ typedef __darwin_pthread_attr_t pthread_
 typedef unsigned long __darwin_pthread_key_t;
 typedef __darwin_pthread_key_t pthread_key_t;
 
-int pthread_create(pthread_t *, const pthread_attr_t *,  // C-warning{{declaration of built-in function 'pthread_create' requires inclusion of the header <pthread.h>}}
+int pthread_create(pthread_t *, const pthread_attr_t *,
                    void *(*)(void *), void *);
 
 int pthread_setspecific(pthread_key_t key, const void *value);

Modified: cfe/branches/release_90/test/Sema/implicit-builtin-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_90/test/Sema/implicit-builtin-decl.c?rev=367528&r1=367527&r2=367528&view=diff
==============================================================================
--- cfe/branches/release_90/test/Sema/implicit-builtin-decl.c (original)
+++ cfe/branches/release_90/test/Sema/implicit-builtin-decl.c Thu Aug  1 02:03:00 2019
@@ -55,14 +55,17 @@ main(int argc, char *argv[])
 
 void snprintf() { }
 
-// PR8316
-void longjmp(); // expected-warning{{declaration of built-in function 'longjmp' requires inclusion of the header <setjmp.h>}}
+// PR8316 & PR40692
+void longjmp(); // expected-warning{{declaration of built-in function 'longjmp' requires the declaration of the 'jmp_buf' type, commonly provided in the header <setjmp.h>.}}
 
 extern float fmaxf(float, float);
 
 struct __jmp_buf_tag {};
-void sigsetjmp(struct __jmp_buf_tag[1], int); // expected-warning{{declaration of built-in function 'sigsetjmp' requires inclusion of the header <setjmp.h>}}
+void sigsetjmp(struct __jmp_buf_tag[1], int); // expected-warning{{declaration of built-in function 'sigsetjmp' requires the declaration of the 'jmp_buf' type, commonly provided in the header <setjmp.h>.}}
 
 // CHECK:     FunctionDecl {{.*}} <line:[[@LINE-2]]:1, col:44> col:6 sigsetjmp '
 // CHECK-NOT: FunctionDecl
 // CHECK:     ReturnsTwiceAttr {{.*}} <{{.*}}> Implicit
+
+// PR40692
+void pthread_create(); // no warning expected




More information about the llvm-branch-commits mailing list