gallivm: Fix lp_build_print_value of smaller integer types.
authorJosé Fonseca <jfonseca@vmware.com>
Thu, 6 Dec 2012 08:50:46 +0000 (08:50 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 6 Dec 2012 15:58:40 +0000 (15:58 +0000)
They need to be converted to the native integer type to prevent garbage
in higher order bits from being printed.

Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/auxiliary/gallivm/lp_bld_printf.c

index 0de6a0882ba6eff0e660b1a240c058e3b99887a6..7a6bbd960bee1331aa0e6c05455ecb0bab8a4179 100644 (file)
@@ -125,8 +125,19 @@ lp_build_print_value(struct gallivm_state *gallivm,
       params[2] = value;
    } else {
       for (i = 0; i < length; ++i) {
+         LLVMValueRef param;
          util_strncat(format, type_fmt, sizeof(format) - strlen(format) - 1);
-         params[2 + i] = LLVMBuildExtractElement(builder, value, lp_build_const_int32(gallivm, i), "");
+         param = LLVMBuildExtractElement(builder, value, lp_build_const_int32(gallivm, i), "");
+         if (type_kind == LLVMIntegerTypeKind &&
+             LLVMGetIntTypeWidth(type_ref) < sizeof(int) * 8) {
+            LLVMTypeRef int_type = LLVMIntTypeInContext(gallivm->context, sizeof(int) * 8);
+            if (LLVMGetIntTypeWidth(type_ref) == 8) {
+               param = LLVMBuildZExt(builder, param, int_type, "");
+            } else {
+               param = LLVMBuildSExt(builder, param, int_type, "");
+            }
+         }
+         params[2 + i] = param;
       }
    }