[cfe-dev] Testcase for LLVM PR9350

Andrew Rogers via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 6 15:05:46 PST 2017


Hi,

 

This is a (tested!) patch to add checks that both pre-increment and pre-decrement don’t overflow, for both char and short integer types (since they’re both narrower than int), as per the problem fixed in PR9350.

 

Thanks, Andrew R

 

From: Friedman, Eli [mailto:efriedma at codeaurora.org] 
Sent: 4 January 2017 6:42 pm
To: andrew.rogers at cantab.net; cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] Testcase for LLVM PR9350

 

On 1/3/2017 2:28 PM, via cfe-dev wrote:

Hi clang devs, 

 

I was looking at PR9350 and saw that Eli added a test to check LLVM doesn't overflow on [signed] char increment:

 

--- cfe/trunk/test/CodeGen/integer-overflow.c 2011/03/02 01:43:30 126815
+++ cfe/trunk/test/CodeGen/integer-overflow.c 2011/03/02 01:49:12 126816
@@ -50,11 +50,17 @@
   // TRAPV_HANDLER: foo(
   --a;
   
-  
   // -fwrapv should turn off inbounds for GEP's, PR9256
   extern int* P;
   ++P;
   // DEFAULT: getelementptr inbounds i32*
   // WRAPV: getelementptr i32*
   // TRAPV: getelementptr inbounds i32*
+
+  // PR9350: char increment never overflows.
+  extern volatile signed char PR9350;
+  // DEFAULT: add i8 {{.*}}, 1
+  // WRAPV: add i8 {{.*}}, 1
+  // TRAPV: add i8 {{.*}}, 1
+  ++PR9350;
}

 

http://llvm.org/viewvc/llvm-project?view=revision <http://llvm.org/viewvc/llvm-project?view=revision&revision=126816> &revision=126816

 

Presumably the logic about promotion to int applies the same as in the argument John gave in PR9350 since 6.5.3.1 §3 says "the prefix -- operator is analogous to the prefix ++ operator, except that the value of the operand is decremented".

 

Would it therefore make sense to add the equivalent test to integer-overflow.c that decrement of a [signed] char didn't ever cause underflow:

 

  // DEFAULT: sub i8 {{.*}}, 1
  // WRAPV: sub i8 {{.*}}, 1
  // TRAPV: sub i8 {{.*}}, 1
  --PR9350;

 


Yes, it probably makes sense to add a testcase like that.  Patch welcome.

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170106/ceebe95f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm-pr9350-test-improvement.patch
Type: application/octet-stream
Size: 1582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170106/ceebe95f/attachment.obj>


More information about the cfe-commits mailing list