This is an archive of the discontinued LLVM Phabricator instance.

[asan][nfc] Fixed test failing on windows due to different printf behaviour.
ClosedPublic

Authored by oontvoo on Mar 12 2021, 6:01 PM.

Details

Summary

%p reported prints upper case hex chars on Windows.
The fix is to switch to using %#lx

Diff Detail

Event Timeline

oontvoo requested review of this revision.Mar 12 2021, 6:01 PM
oontvoo created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2021, 6:01 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
oontvoo retitled this revision from [asan] Fixed test failing on windows due to different printf behaviour. to [asan][nfc] Fixed test failing on windows due to different printf behaviour..Mar 12 2021, 7:44 PM
thakis added a subscriber: thakis.Mar 15 2021, 6:53 AM
thakis added inline comments.
compiler-rt/test/asan/TestCases/wild_pointer.cpp
17

As far as I know, Windows doesn't print the 0x, which makes the [[ADDR]] capture fail I think. And then the CHECK on the next line would fail too since [[ADDR]] doesn't include the 0x.

So this comment should say "Windows omits the 0x prefix" instead, since that's the problem.

unsigned long is 32-bit on 64-bit Windows (https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models) so if you want to keep the current approach you want to use uintptr_t and PRIxPTR from stdint.h and inttypes.h respectively:

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
int main() {
	printf("%#" PRIxPTR "\n", (uintptr_t)1231);
}

(Unrelated: Please upload diffs with -U9999)

oontvoo updated this revision to Diff 330656.Mar 15 2021, 7:33 AM

Use PRIxPTR

oontvoo marked an inline comment as done.Mar 15 2021, 7:35 AM
oontvoo added inline comments.
compiler-rt/test/asan/TestCases/wild_pointer.cpp
17

(Unrelated: Please upload diffs with -U9999)

This is the full file (it's not being truncated ...)

oontvoo updated this revision to Diff 330658.Mar 15 2021, 7:53 AM
oontvoo marked an inline comment as done.

updated comment

thakis accepted this revision.Mar 15 2021, 7:54 AM

Thanks!

This revision is now accepted and ready to land.Mar 15 2021, 7:54 AM
This revision was landed with ongoing or failed builds.Mar 15 2021, 7:59 AM
This revision was automatically updated to reflect the committed changes.