aaron.ballman created this revision.
aaron.ballman added reviewers: rengolin, chatur01, rsmith.
aaron.ballman added inline comments.


================
Comment at: test/Sema/builtins.c:228
                                     // expected-note {{change size argument to 
be the size of the destination}}
-                                   
+
         __builtin___strlcat_chk(buf, b, sizeof(b), __builtin_object_size(buf, 
0)); // expected-warning {{size argument in '__builtin___strlcat_chk' call 
appears to be size of the source; expected the size of the destination}} \
----------------
I'll revert this sneaky whitespace either as part of the commit, or as an 
updated patch if one is required.


r242675 changed the signature for the signbit builtin but did not introduce 
proper semantic checking to ensure the arguments are as-expected. This lead to 
regressions like the one reported in PR28172 where codegen would crash. This 
patch addresses this by properly grouping the signbit builtins along with the 
other fp classification builtins.


Repository:
  rC Clang

https://reviews.llvm.org/D47435

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/builtins.c


Index: test/Sema/builtins.c
===================================================================
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -225,7 +225,7 @@
 
         strlcat(buf, b, sizeof(b)); // expected-warning {{size argument in 
'strlcat' call appears to be size of the source; expected the size of the 
destination}} \
                                     // expected-note {{change size argument to 
be the size of the destination}}
-                                   
+
         __builtin___strlcat_chk(buf, b, sizeof(b), __builtin_object_size(buf, 
0)); // expected-warning {{size argument in '__builtin___strlcat_chk' call 
appears to be size of the source; expected the size of the destination}} \
                                                                                
    // expected-note {{change size argument to be the size of the destination}} 
\
                                                                                
   // expected-warning {{'__builtin___strlcat_chk' will always overflow 
destination buffer}}
@@ -253,3 +253,17 @@
   __sync_fetch_and_add(ptr, 1); // expected-error{{address argument to atomic 
builtin cannot be const-qualified ('const int *' invalid)}}
   __atomic_fetch_add(ptr, 1, 0);  // expected-error {{address argument to 
atomic operation must be a pointer to non-const type ('const int *' invalid)}}
 }
+
+void test22(void) {
+  (void)__builtin_signbit(); // expected-error{{too few arguments to function 
call, expected 1, have 0}}
+  (void)__builtin_signbit(1.0, 2.0, 3.0); // expected-error{{too many 
arguments to function call, expected 1, have 3}}
+  (void)__builtin_signbit(1); // expected-error {{floating point 
classification requires argument of floating point type (passed in 'int')}}
+
+  (void)__builtin_signbitf(); // expected-error{{too few arguments to function 
call, expected 1, have 0}}
+  (void)__builtin_signbitf(1.0, 2.0, 3.0); // expected-error{{too many 
arguments to function call, expected 1, have 3}}
+  (void)__builtin_signbitf(1);
+
+  (void)__builtin_signbitl(); // expected-error{{too few arguments to function 
call, expected 1, have 0}}
+  (void)__builtin_signbitl(1.0, 2.0, 3.0); // expected-error{{too many 
arguments to function call, expected 1, have 3}}
+  (void)__builtin_signbitl(1);
+}
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -919,6 +919,9 @@
   case Builtin::BI__builtin_isinf_sign:
   case Builtin::BI__builtin_isnan:
   case Builtin::BI__builtin_isnormal:
+  case Builtin::BI__builtin_signbit:
+  case Builtin::BI__builtin_signbitf:
+  case Builtin::BI__builtin_signbitl:
     if (SemaBuiltinFPClassification(TheCall, 1))
       return ExprError();
     break;


Index: test/Sema/builtins.c
===================================================================
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -225,7 +225,7 @@
 
         strlcat(buf, b, sizeof(b)); // expected-warning {{size argument in 'strlcat' call appears to be size of the source; expected the size of the destination}} \
                                     // expected-note {{change size argument to be the size of the destination}}
-				    
+
         __builtin___strlcat_chk(buf, b, sizeof(b), __builtin_object_size(buf, 0)); // expected-warning {{size argument in '__builtin___strlcat_chk' call appears to be size of the source; expected the size of the destination}} \
                                                                                    // expected-note {{change size argument to be the size of the destination}} \
 				                                                   // expected-warning {{'__builtin___strlcat_chk' will always overflow destination buffer}}
@@ -253,3 +253,17 @@
   __sync_fetch_and_add(ptr, 1); // expected-error{{address argument to atomic builtin cannot be const-qualified ('const int *' invalid)}}
   __atomic_fetch_add(ptr, 1, 0);  // expected-error {{address argument to atomic operation must be a pointer to non-const type ('const int *' invalid)}}
 }
+
+void test22(void) {
+  (void)__builtin_signbit(); // expected-error{{too few arguments to function call, expected 1, have 0}}
+  (void)__builtin_signbit(1.0, 2.0, 3.0); // expected-error{{too many arguments to function call, expected 1, have 3}}
+  (void)__builtin_signbit(1); // expected-error {{floating point classification requires argument of floating point type (passed in 'int')}}
+
+  (void)__builtin_signbitf(); // expected-error{{too few arguments to function call, expected 1, have 0}}
+  (void)__builtin_signbitf(1.0, 2.0, 3.0); // expected-error{{too many arguments to function call, expected 1, have 3}}
+  (void)__builtin_signbitf(1);
+
+  (void)__builtin_signbitl(); // expected-error{{too few arguments to function call, expected 1, have 0}}
+  (void)__builtin_signbitl(1.0, 2.0, 3.0); // expected-error{{too many arguments to function call, expected 1, have 3}}
+  (void)__builtin_signbitl(1);
+}
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -919,6 +919,9 @@
   case Builtin::BI__builtin_isinf_sign:
   case Builtin::BI__builtin_isnan:
   case Builtin::BI__builtin_isnormal:
+  case Builtin::BI__builtin_signbit:
+  case Builtin::BI__builtin_signbitf:
+  case Builtin::BI__builtin_signbitl:
     if (SemaBuiltinFPClassification(TheCall, 1))
       return ExprError();
     break;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to