From 2cbb76ac888bb1208c71c370142480dab13c60b3 Mon Sep 17 00:00:00 2001 From: "Zdunowski, Piotr" Date: Tue, 27 Mar 2018 11:09:37 +0200 Subject: [PATCH] Fix for reading pointers from printf surface on 32bit configurations. Change-Id: I2b7511b33de6f20f612e87a7f32dd6fd5356b55a --- runtime/program/print_formatter.cpp | 8 ++++++-- unit_tests/program/printf_helper_tests.cpp | 8 +++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/runtime/program/print_formatter.cpp b/runtime/program/print_formatter.cpp index 3d453af463..a676cbffde 100644 --- a/runtime/program/print_formatter.cpp +++ b/runtime/program/print_formatter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -119,6 +119,7 @@ void PrintFormatter::stripVectorTypeConversion(char *format) { size_t PrintFormatter::printToken(char *output, size_t size, const char *formatString) { PRINTF_DATA_TYPE type(PRINTF_DATA_TYPE::INVALID); + size_t ret = 0; read(&type); switch (type) { @@ -133,7 +134,10 @@ size_t PrintFormatter::printToken(char *output, size_t size, const char *formatS case PRINTF_DATA_TYPE::LONG: return typedPrintToken(output, size, formatString); case PRINTF_DATA_TYPE::POINTER: - return typedPrintToken(output, size, formatString); + ret = typedPrintToken(output, size, formatString); + // always pad read data to 8 bytes when handling pointers + offset += 8 - sizeof(void *); + return ret; case PRINTF_DATA_TYPE::DOUBLE: return typedPrintToken(output, size, formatString); case PRINTF_DATA_TYPE::VECTOR_BYTE: diff --git a/unit_tests/program/printf_helper_tests.cpp b/unit_tests/program/printf_helper_tests.cpp index 580f7d004c..0e39edd2a3 100644 --- a/unit_tests/program/printf_helper_tests.cpp +++ b/unit_tests/program/printf_helper_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -748,6 +748,12 @@ TEST_F(PrintFormatterTest, GivenPrintfFormatWhenPointerThenInsertAddress) { // channel count storeData(reinterpret_cast(&temp)); + // on 32bit configurations add extra 4 bytes when storing pointers, IGC always stores pointers on 8 bytes + if (!is64bit) { + uint32_t padding = 0; + storeData(padding); + } + char actualOutput[PrintFormatter::maxPrintfOutputLength]; char referenceOutput[PrintFormatter::maxPrintfOutputLength];