[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-14 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D119528#3319955 , @aaron.ballman 
wrote:

> LGTM, thank you for the additional test coverage! Do you need me to commit on 
> your behalf? If so, what name and email address would you like me to use for 
> patch attribution?

Thanks but I can push it on my own ;^)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

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


[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-14 Thread Jun Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeffd6dd63a65: [Clang][Sema] Add a missing regression test 
about Wliteral-range (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L; // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L; // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning 

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you for the additional test coverage! Do you need me to commit on 
your behalf? If so, what name and email address would you like me to use for 
patch attribution?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

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


[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-14 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D119528#3318913 , @aaron.ballman 
wrote:

> In D119528#3316311 , @junaire wrote:
>
>>> I think we should probably have test coverage for `long double` as well, 
>>> but I also wonder whether it makes sense to add coverage for the small 
>>> floating-point types (like `_Float16`) as well, or whether we already have 
>>> coverage for those elsewhere.
>>
>> Test long double is fine for me. But I'm not really sure if we need to test 
>> for these half-precision floats, as they are part of clang language 
>> extension and not supported in all targets. IMHO, maybe we can just simply 
>> test these normal or standard floats first?
>
> I'm fine with that approach. Thanks for adding the `long double` support, but 
> it looks like the precommit CI spotted an issue:
>
>   FAIL: Clang :: Sema/warn-literal-range.c (12332 of 29830)
>    TEST 'Clang :: Sema/warn-literal-range.c' FAILED 
> 
>   Script:
>   --
>   : 'RUN: at line 1';   
> c:\ws\w32-1\llvm-project\premerge-checks\build\bin\clang.exe -cc1 
> -internal-isystem 
> c:\ws\w32-1\llvm-project\premerge-checks\build\lib\clang\15.0.0\include 
> -nostdsysteminc -std=c99 -verify 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c
>   --
>   Exit Code: 1
>   
>   Command Output (stdout):
>   --
>   $ ":" "RUN: at line 1"
>   $ "c:\ws\w32-1\llvm-project\premerge-checks\build\bin\clang.exe" "-cc1" 
> "-internal-isystem" 
> "c:\ws\w32-1\llvm-project\premerge-checks\build\lib\clang\15.0.0\include" 
> "-nostdsysteminc" "-std=c99" "-verify" 
> "C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c"
>   # command stderr:
>   error: 'warning' diagnostics expected but not seen: 
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 29: magnitude of floating-point constant too small for type 'long 
> double'; minimum is 3.64519953188247460253E-4951
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 31: magnitude of floating-point constant too large for type 'long 
> double'; maximum is 1.18973149535723176502E+4932
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 35: magnitude of floating-point constant too small for type 'long 
> double'; minimum is 3.64519953188247460253E-4951
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 37: magnitude of floating-point constant too large for type 'long 
> double'; maximum is 1.18973149535723176502E+4932
>   
>   error: 'warning' diagnostics seen but not expected: 
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 29: magnitude of floating-point constant too small for type 'long 
> double'; minimum is 4.9406564584124654E-324
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 31: magnitude of floating-point constant too large for type 'long 
> double'; maximum is 1.7976931348623157E+308
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 35: magnitude of floating-point constant too small for type 'long 
> double'; minimum is 4.9406564584124654E-324
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 37: magnitude of floating-point constant too large for type 'long 
> double'; maximum is 1.7976931348623157E+308
>   
>   8 errors generated.
>   
>   
>   error: command failed with exit status: 1
>   
>   --
>   
>   

Thanks for spending time looking at the CI issue, I thought it was something 
wrong with itself!

> You might need to add a target triple to the test to specify exactly which 
> target you are testing for. Bonus points if you pick a second target with 
> different range of values. You can do that with something like:
>
>   // RUN: %clang_cc1 -triple=whatever -std=c99 -verify=whatever %s
>   // RUN: %clang_cc1 -triple=whatever-else -std=c99 -verify=whatever-else %s
>   
>   long double ld5 = 0x0.42p+42000L; // whatever-warning {{magnitude of 
> floating-point constant too large for type 'long double'; maximum is 
> 1.18973149535723176502E+4932}} \
> 
> whatever-else-warning {{magnitude of floating-point constant too large for 
> type 'long double'; maximum is 12}} \
>
> (the identifier after `-verify=` is used in place of the `expected` in 
> diagnostic verification so you can vary which warnings are checked against 
> which RUN lines.)

Thanks for telling me these about the regression tests! But I have no LLVM 
development set up in Windows so I guess one triple test should be fine. Maybe 
I can use the info given by the 

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-14 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 408407.
junaire added a comment.

Add triple info to avoid tests failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L; // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L; // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D119528#3316311 , @junaire wrote:

>> I think we should probably have test coverage for `long double` as well, but 
>> I also wonder whether it makes sense to add coverage for the small 
>> floating-point types (like `_Float16`) as well, or whether we already have 
>> coverage for those elsewhere.
>
> Test long double is fine for me. But I'm not really sure if we need to test 
> for these half-precision floats, as they are part of clang language extension 
> and not supported in all targets. IMHO, maybe we can just simply test these 
> normal or standard floats first?

I'm fine with that approach. Thanks for adding the `long double` support, but 
it looks like the precommit CI spotted an issue:

  FAIL: Clang :: Sema/warn-literal-range.c (12332 of 29830)
   TEST 'Clang :: Sema/warn-literal-range.c' FAILED 

  Script:
  --
  : 'RUN: at line 1';   
c:\ws\w32-1\llvm-project\premerge-checks\build\bin\clang.exe -cc1 
-internal-isystem 
c:\ws\w32-1\llvm-project\premerge-checks\build\lib\clang\15.0.0\include 
-nostdsysteminc -std=c99 -verify 
C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c
  --
  Exit Code: 1
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ "c:\ws\w32-1\llvm-project\premerge-checks\build\bin\clang.exe" "-cc1" 
"-internal-isystem" 
"c:\ws\w32-1\llvm-project\premerge-checks\build\lib\clang\15.0.0\include" 
"-nostdsysteminc" "-std=c99" "-verify" 
"C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c"
  # command stderr:
  error: 'warning' diagnostics expected but not seen: 
  
File 
C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
Line 29: magnitude of floating-point constant too small for type 'long double'; 
minimum is 3.64519953188247460253E-4951
  
File 
C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
Line 31: magnitude of floating-point constant too large for type 'long double'; 
maximum is 1.18973149535723176502E+4932
  
File 
C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
Line 35: magnitude of floating-point constant too small for type 'long double'; 
minimum is 3.64519953188247460253E-4951
  
File 
C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
Line 37: magnitude of floating-point constant too large for type 'long double'; 
maximum is 1.18973149535723176502E+4932
  
  error: 'warning' diagnostics seen but not expected: 
  
File 
C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
Line 29: magnitude of floating-point constant too small for type 'long double'; 
minimum is 4.9406564584124654E-324
  
File 
C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
Line 31: magnitude of floating-point constant too large for type 'long double'; 
maximum is 1.7976931348623157E+308
  
File 
C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
Line 35: magnitude of floating-point constant too small for type 'long double'; 
minimum is 4.9406564584124654E-324
  
File 
C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
Line 37: magnitude of floating-point constant too large for type 'long double'; 
maximum is 1.7976931348623157E+308
  
  8 errors generated.
  
  
  error: command failed with exit status: 1
  
  --
  
  

You might need to add a target triple to the test to specify exactly which 
target you are testing for. Bonus points if you pick a second target with 
different range of values. You can do that with something like:

  // RUN: %clang_cc1 -triple=whatever -std=c99 -verify=whatever %s
  // RUN: %clang_cc1 -triple=whatever-else -std=c99 -verify=whatever-else %s
  
  long double ld5 = 0x0.42p+42000L; // whatever-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}} \

whatever-else-warning {{magnitude of floating-point constant too large for type 
'long double'; maximum is 12}} \

(the identifier after `-verify=` is used in place of the `expected` in 
diagnostic verification so you can vary which warnings are checked against 
which RUN lines.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

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


[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 408134.
junaire added a comment.

Add missing blank.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L;  // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L;  // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
___
cfe-commits 

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 408133.
junaire added a comment.

long double should use `L` as literal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}
+long double ld3 = 0x0.42p42;  // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
+long double ld3 = 0x0.42p42;  // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
___

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

> I think we should probably have test coverage for `long double` as well, but 
> I also wonder whether it makes sense to add coverage for the small 
> floating-point types (like `_Float16`) as well, or whether we already have 
> coverage for those elsewhere.

Test long double is fine for me. But I'm not really sure if we need to test for 
these half-precision floats, as they are part of clang language extension and 
not supported in all targets. IMHO, maybe we can just simply test these normal 
or standard floats first?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

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


[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 408129.
junaire added a comment.

Add tests for long double.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 4.9E-325; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+long double ld2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld3 = 0x0.42p42; // no-warning
+
+long double ld4 = 0x0.42p-4200; // expected-warning {{magnitude of 
floating-point constant too small for type 'double'; minimum is 
4.9406564584124654E-324}}
+
+long double ld5 = 0x0.42p+4200; // expected-warning {{magnitude of 
floating-point constant too large for type 'double'; maximum is 
1.7976931348623157E+308}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 4.9E-325; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+long double ld2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld3 = 0x0.42p42; // no-warning
+
+long double ld4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+long double ld5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Sema/warn-literal-range.c:25
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}

I think we should probably have test coverage for `long double` as well, but I 
also wonder whether it makes sense to add coverage for the small floating-point 
types (like `_Float16`) as well, or whether we already have coverage for those 
elsewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

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


[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added a reviewer: aaron.ballman.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds a missing test, covering the different kinds of floating-point
literals, like hexadecimal floats, and testing extreme cases & normal cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits