Skip to content

Commit

Permalink
Use the correct location to overapproximate unions with floats
Browse files Browse the repository at this point in the history
The issue does not only occur at writes (ae94f3b), so we put the overapproximation at the declaration instead.
  • Loading branch information
schuessf committed Nov 27, 2024
1 parent fdd0ec5 commit 860c6cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2252,11 +2252,21 @@ public Result visit(final IDispatcher main, final IASTSimpleDeclaration node) {
final CDeclaration cDec = declResult.getDeclaration();
cDec.setStorageClass(storageClass);

// are we in prerun mode?
// all unions should be on heap
if (mIsPrerun && CStructOrUnion.isUnion(cDec.getType().getUnderlyingType())
&& storageClass != CStorageClass.TYPEDEF) {
addToVariablesOnHeap(declarator.getName());
final CType type = cDec.getType().getUnderlyingType();
if (CStructOrUnion.isUnion(type) && storageClass != CStorageClass.TYPEDEF) {
// For the memory model HoenickeLindenmann_Original, unions in floats are not handled properly,
// therefore we overapproximate them instead to avoid any unsoundness.
if (mSettings.getMemoryModelPreference() == MemoryModel.HoenickeLindenmann_Original
&& Arrays.stream(((CStructOrUnion) type).getFieldTypes()).anyMatch(CType::isFloatingType)) {
final Statement stmt = ExpressionTranslation.modelUnsupportedFeature(loc,
"union with floats in the HoenickeLindenmann_Original memory model");
intermediateResults.add(new ExpressionResultBuilder().addStatement(stmt).build());
}
// are we in prerun mode?
// all unions should be on heap
if (mIsPrerun) {
addToVariablesOnHeap(declarator.getName());
}
}

if (cDec.getType() instanceof CFunction && storageClass != CStorageClass.TYPEDEF) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2602,17 +2602,11 @@ private List<Statement> getWriteCallArray(final ILocation loc, final HeapLValue
private List<Statement> getWriteCallStruct(final ILocation loc, final HeapLValue hlv, final Expression value,
final CStructOrUnion valueType, final HeapWriteMode writeMode) {
final List<Statement> stmt = new ArrayList<>();
final boolean checkForFloats = CStructOrUnion.isUnion(valueType)
&& mSettings.getMemoryModelPreference() == MemoryModel.HoenickeLindenmann_Original;
for (final String fieldId : valueType.getFieldIds()) {
final Expression startAddress = hlv.getAddress();
final Expression newStartAddressBase = MemoryHandler.getPointerBaseAddress(startAddress, loc);
final Expression newStartAddressOffset = MemoryHandler.getPointerOffset(startAddress, loc);
final CType fieldType = valueType.getFieldType(fieldId);
if (checkForFloats && fieldType.getUnderlyingType().isFloatingType()) {
stmt.add(ExpressionTranslation.modelUnsupportedFeature(loc,
"write for union with floats in the HoenickeLindenmann_Original memory model"));
}
final StructAccessExpression sae = ExpressionFactory.constructStructAccessExpression(loc, value, fieldId);
final Offset fieldOffset = mTypeSizeAndOffsetComputer.constructOffsetForField(loc, valueType, fieldId);
if (fieldOffset.isBitfieldOffset()) {
Expand Down

0 comments on commit 860c6cc

Please sign in to comment.