From 57cd804953c56a3a46ce17aac1ca5dafde5d2fc8 Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 15 Apr 2024 15:36:49 +0200 Subject: [PATCH] force gcc optimization to O1 in KWDGPODiscretizer With gcc 12.2.0 (on debian 12), gcc seems too agressive. The only way to fix a segmentation fault is to force the optimization level to O1 instead of O2. The segmentation fault occured while accessing the variable cell1 which is NULL. By adding the following (unnecessary) line, the segmentation fault vanishes: if (cell1==NULL or cell2==NULL) exit(1); --- .../KWDataGridPostOptimizer.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Learning/KWDataPreparation/KWDataGridPostOptimizer.cpp b/src/Learning/KWDataPreparation/KWDataGridPostOptimizer.cpp index 14b01fae9..92c65756e 100644 --- a/src/Learning/KWDataPreparation/KWDataGridPostOptimizer.cpp +++ b/src/Learning/KWDataPreparation/KWDataGridPostOptimizer.cpp @@ -560,6 +560,19 @@ void KWDGPODiscretizer::InitializeCellFrequencyVector(KWDGPOCellFrequencyVector* // Index de l'attribut a post-optimiser (et donc a ignorer pour le calcul de la signature exogene static int nKWDGPODiscretizerPostOptimizationAttributeIndex = -1; +// Bug detecte sur debian 12 avec la version 12.2.0 de gcc. Ce bug apparait en release mais pas en debug. +// On force la compilation en O1 car il doit y avoir une sur-optimisation de gcc en mode 02 : +// il y a un segmentation fault, gdb indique que cell1 est a NULL. +// En ajoutant la ligne suivante (inutile) apres les cast, le bug disparait +// if (cell1==NULL or cell2==NULL) exit(1); +// Bug similaire dans KWSortableIndex.h, classe KWIntVectorSorter +#if defined NDEBUG && defined __GNUC__ && !defined __clang__ +#if __GNUC__ >= 12 +#pragma GCC push_options +#pragma GCC optimize("O1") +#endif +#endif + // Fonction de comparaison de deux cellules basee sur leur signature exogene int KWDGPODiscretizerCompareCell(const void* elem1, const void* elem2) { @@ -596,6 +609,12 @@ int KWDGPODiscretizerCompareCell(const void* elem1, const void* elem2) return 0; } +#if defined NDEBUG && defined __GNUC__ && !defined __clang__ +#if __GNUC__ >= 12 +#pragma GCC pop_options +#endif +#endif + void KWDGPODiscretizer::InitializeHashCellDictionary(NumericKeyDictionary* nkdHashCells, const KWDataGrid* dataGrid) const { @@ -1512,6 +1531,14 @@ int KWDGPOGrouperCompareCell(const void* elem1, const void* elem2) cell2 = cast(KWDGCell*, *(Object**)elem2); assert(cell1->GetAttributeNumber() == cell2->GetAttributeNumber()); + //cout<<"KWDGPOGrouperCompareCell"<WriteString(); + // if (cell2!=NULL) cout<<"cell2: "<WriteString()<GetAttributeNumber(); nAttribute++) {