Skip to content

Segmentation fault occurred warning: dereferencing type-punned pointer will break strict-aliasing rules

It is not just warning. The generated code is fundamentally wrong.

Summary

The generated code compiled with warning: dereferencing type-punned pointer will break strict-aliasing rules if the optimalization level at least 2: compiled with -O2

Steps and/or TTCN-3 code to reproduce

module proba {

type component CT {}

function f2(in @lazy charstring pl_message) runs on CT {
  log(pl_message)
}
}

What is the current bug behavior?

g++  -c -DLINUX -I/home/ethgasz/TTCNv3/include -Wall -O2 -g -o proba.o proba.cc
proba.cc: In function ‘void proba::start_f2(const COMPONENT&, Lazy_Fuzzy_Expr<CHARSTRING>*)’:
proba.cc:3262:15: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 3262 | ((CHARSTRING&)pl__message).log();
      |               ^~~~~~~~~~~
proba.cc:3269:15: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 3269 | ((CHARSTRING&)pl__message).encode_text(text_buf);
      |               ^~~~~~~~~~~
proba.cc: In function ‘boolean proba::start_ptc_function(const char*, Text_Buf&)’:
proba.cc:3304:15: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 3304 | ((CHARSTRING&)pl__message).decode_text(function_arguments);
      |               ^~~~~~~~~~~
proba.cc:3307:15: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 3307 | ((CHARSTRING&)pl__message).log();
      |               ^~~~~~~~~~~

What is the expected correct behavior?

No g++ warning

Titan version

latest head:

commit 999bffa6 (HEAD -> master, origin/master, origin/HEAD) Author: Botond Baranyi botond.baranyi@ericsson.com Date: Fri Oct 27 18:27:55 2023 +0200

Fixed lazy/fuzzy variables to work in redirects (issue #686)

Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com>
Edited by Gábor Szalai