[cfe-dev] Question about ASTContext::getPromotedIntegerType() function

JinGu Kang jingu at codeplay.com
Tue Jul 16 04:01:01 PDT 2013


Hi all,

I have a question about ASTContext::getPromotedIntegerType() function.

I have tested a code as following:

source code:
int main()
{
   volatile unsigned short x;
   volatile unsigned short y;
   volatile unsigned short result;

   x = 8;
   y = 2;

   result = x / y;

   return 0;
}

Generated IR from clang:
   6 define i32 @main() #0 {
   7 entry:
   8   %retval = alloca i32, align 4
   9   %x = alloca i16, align 2
  10   %y = alloca i16, align 2
  11   %result = alloca i16, align 2
  12   store i32 0, i32* %retval
  13   store volatile i16 8, i16* %x, align 2
  14   store volatile i16 2, i16* %y, align 2
  15   %0 = load volatile i16* %x, align 2
  16   %conv = zext i16 %0 to i32
  17   %1 = load volatile i16* %y, align 2
  18   %conv1 = zext i16 %1 to i32
  19   %div = sdiv i32 %conv, %conv1
  20   %conv2 = trunc i32 %div to i16
  21   store volatile i16 %conv2, i16* %result, align 2
  22   ret i32 0
  23 }

I expected "udiv" instruction on line 19 but there was "sdiv" 
instruction because of "ASTContext::getPromotedIntegerType()" function 
promotes "unsigned short" to "int".

Could someone explain why this function returns "IntTy" when 
"PromotableSize" is not same with "IntSize"? I think that the line of 
"ASTContext::getPromotedIntegerType()" function should be changed.
ex)
return (PromotableSize != IntSize) ? IntTy : UnsignedIntTy;
--> return UnsignedIntTy;

Thanks,
JinGu Kang


-- 
JinGu Kang
Codeplay Software Ltd
45 York Place, Edinburgh, EH1 3HP
Tel: 0131 466 0503
Fax: 0131 557 6600
Website: http://www.codeplay.com
Twitter: https://twitter.com/codeplaysoft

This email and any attachments may contain confidential and /or privileged information and is for use by the addressee only. If you are not the intended recipient, please notify Codeplay Software Ltd immediately and delete the message from your computer. You may not copy or forward it,or use or disclose its contents to any other person. Any views or other information in this message which do not relate to our business are not authorized by Codeplay software Ltd, nor does this message form part of any contract unless so stated.
As internet communications are capable of data corruption Codeplay Software Ltd does not accept any responsibility for any changes made to this message after it was sent. Please note that Codeplay Software Ltd does not accept any liability or responsibility for viruses and it is your responsibility to scan any attachments.
Company registered in England and Wales, number: 04567874
Registered office: 81 Linkfield Street, Redhill RH1 6BY

-------------- next part --------------
Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp	(revision 186398)
+++ lib/AST/ASTContext.cpp	(working copy)
@@ -4369,7 +4369,7 @@
   uint64_t PromotableSize = getIntWidth(Promotable);
   uint64_t IntSize = getIntWidth(IntTy);
   assert(Promotable->isUnsignedIntegerType() && PromotableSize <= IntSize);
-  return (PromotableSize != IntSize) ? IntTy : UnsignedIntTy;
+  return UnsignedIntTy;
 }
 
 /// \brief Recurses in pointer/array types until it finds an objc retainable


More information about the cfe-dev mailing list