[PATCH] [Sema] Prevent crash while trying to merge types

Davide Italiano dccitaliano at gmail.com
Thu Apr 23 15:46:05 PDT 2015


Hi rsmith, aaron.ballman,

This fixes bug 23086.
__builtin_isnan(...) causes clang to crash in sema. The proposed patch is an attempt to fix.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D9235

Files:
  lib/Sema/SemaDecl.cpp
  test/Sema/crash-invalid-builtin.c

Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2985,6 +2985,11 @@
     const FunctionProtoType *NewProto
       = New->getType()->getAs<FunctionProtoType>();
 
+    // The function prototype might be null, in which case
+    // there's not point to keep going and trying to merge types.
+    if (!OldProto || !NewProto)
+      return true;
+
     // Determine whether this is the GNU C extension.
     QualType MergedReturn = Context.mergeTypes(OldProto->getReturnType(),
                                                NewProto->getReturnType());
Index: test/Sema/crash-invalid-builtin.c
===================================================================
--- test/Sema/crash-invalid-builtin.c
+++ test/Sema/crash-invalid-builtin.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsyntax-only -verify %s
+// PR23086
+
+__builtin_isinf(...); // expected-warning {{type specifier missing, defaults to 'int'}} expected-error {{ISO C requires a named parameter before '...'}}

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9235.24336.patch
Type: text/x-patch
Size: 1096 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150423/9b10dc09/attachment.bin>


More information about the cfe-commits mailing list