concurrencykit / ck

Concurrency primitives, safe memory reclamation mechanisms and non-blocking (including lock-free) data structures designed to aid in the research, design and implementation of high performance concurrent systems developed in C99+.
http://concurrencykit.org/
Other
2.35k stars 312 forks source link

ck_pr: fix ptr output operand widths on x86 and x86_64 #175

Closed markjdb closed 3 years ago

markjdb commented 3 years ago

Operations on a variable of type "ptr" specify that the output operand can be a memory address. Most such operations specify that the output operand is of type char, so it has width 1. Convert these to uint64_t on x86_64 and uint32_t on x86.

No functional change intended. With clang 12.0.1 there is no difference in the generated code before and after this change.

The compiler needs to know the true width of the destination operand in some cases. In particular, when compiling with LLVM's MemorySanitizer enabled, the generated code updates shadow state to mark variables as initialized (or not) at byte granularity. When instrumenting inline assembly, the compiler uses the width of the output operand(s) to figure out how many bytes of shadow state to update. When the output operand is cast to char, the runtime would only update one byte of shadow state even though the store modified eight bytes of memory. This led to false positives when enabling MSAN in the FreeBSD kernel.