-Wlarger-than warning when using regular expressions c++

76 Views Asked by At

Compiling a program with anything from <regex> leads to -Wlarger-than warning and weirdly long compilation time.

While compiling this code

#include <regex>
int main()
{
    std::regex pattern {R"(\w)"};    
}

with -Wlarger-than=8192 flag I get this warning:

cc1plus: warning: size of ‘*.LASAN0’ 899648 bytes exceeds maximum object size 8192 [-Wlarger-than=]

Moreover, it takes a while to compile and the size of ‘*.LASAN0’ exceeds with greater -0 flags.

Why is this happening? Whats wrong? And is there a way to fix it?

1

There are 1 best solutions below

0
Artyer On

.LASAN0 is the label given to the object passed to __asan_register_globals: It is an array of structs containing information about any global variables, to be used by the AddressSanitizer.

When compiled with another sanitizer (I've reproduced this with, -fsanitize=address,undefined), the other sanitizer might employ a lot of global variables, which adds overhead to the global variable sanitizer.

std::regex is known to take ages to compile. It is just a complicated class. The fact that it needs a structure with ~880KiB of data to compile with ASan and UBSan shows that.

Anything of similar complexity would also have the same warning, so there's nothing wrong per se with your code. Just give a more sensible size to -Wlarger-than (Or ignore it, it's just a warning you enabled).