Skip to content

Commit

Permalink
force gcc optimization to O1 in KWDGPODiscretizer
Browse files Browse the repository at this point in the history
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);
  • Loading branch information
bruno-at-orange committed Apr 15, 2024
1 parent 9591132 commit 57cd804
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Learning/KWDataPreparation/KWDataGridPostOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -1512,6 +1531,14 @@ int KWDGPOGrouperCompareCell(const void* elem1, const void* elem2)
cell2 = cast(KWDGCell*, *(Object**)elem2);
assert(cell1->GetAttributeNumber() == cell2->GetAttributeNumber());

//cout<<"KWDGPOGrouperCompareCell"<<endl;
if (cell1 == NULL)
exit(0);
if (cell2 == NULL)
exit(0);
// if (cell1!=NULL) cout<<"cell1: "<<cell1->WriteString();
// if (cell2!=NULL) cout<<"cell2: "<<cell2->WriteString()<<endl;

// Comparaison
for (nAttribute = 0; nAttribute < cell1->GetAttributeNumber(); nAttribute++)
{
Expand Down

0 comments on commit 57cd804

Please sign in to comment.