[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[creduce-dev] fix for crashes in UnionToStruct



Hi,
I managed to trigger a crash in UnionToStruct in clang_delta when reducing a non-preprocessed file. The problem was that clang_delta considered unions from included files as replacement candidates.
This problem is fixed by the attached patch.

/ Johan

>From 66400f2fb4cff22306e2a213d8f100da6bc3b965 Mon Sep 17 00:00:00 2001
From: Johan Bengtsson <johan.bengtsson@iar.com>
Date: Tue, 22 Dec 2015 16:11:18 +0100
Subject: [PATCH 4/4] Make UnionToStruct skip unions from included files

The UnionToStruct transformation did not check that the considered
unions are declared in the main file.
---
 clang_delta/UnionToStruct.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang_delta/UnionToStruct.cpp b/clang_delta/UnionToStruct.cpp
index 51b16ef..e2b4854 100644
--- a/clang_delta/UnionToStruct.cpp
+++ b/clang_delta/UnionToStruct.cpp
@@ -88,7 +88,7 @@ bool UnionToStructCollectionVisitor::VisitFieldDecl(FieldDecl *FD)
 
 bool UnionToStructCollectionVisitor::VisitRecordDecl(RecordDecl *RD)
 {
-  if (RD->isUnion())
+  if (RD->isUnion() && !ConsumerInstance->isInIncludedFile(RD))
     ConsumerInstance->addOneRecord(RD);
 
   return true;
-- 
2.7.0