Skip to content

[OpenMP] Strict aliasing violation in TargetValue::getValue() #94616

@nikic

Description

@nikic

This bit of code looks a bit suspect:

template <typename T> ompd_rc_t TBaseValue::getValue(T &buf) {
assert(sizeof(T) >= baseTypeSize);
ompd_rc_t ret = getValue(&buf, 1);
if (sizeof(T) > baseTypeSize) {
switch (baseTypeSize) {
case 1:
buf = (T) * ((int8_t *)&buf);
break;
case 2:
buf = (T) * ((int16_t *)&buf);
break;
case 4:
buf = (T) * ((int32_t *)&buf);
break;
case 8:
buf = (T) * ((int64_t *)&buf);
break;
}
}
return ret;
}

This passes in T& buf, then reads into it via getValue() -- this part is fine, as that's essentially done via memcpy.

But then buf is cast to uintN_t *, dereferenced, cast to T and written back to buf. This is not compatible with strict aliasing in C.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions