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
clang.patch (551 Bytes)