Bug 2050569 - vsnprintf using "%Lg" causes wrong result
Summary: vsnprintf using "%Lg" causes wrong result
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: rawhide
Hardware: ppc64le
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 2045699
TreeView+ depends on / blocked
 
Reported: 2022-02-04 09:42 UTC by Mamoru TASAKA
Modified: 2022-02-06 18:11 UTC (History)
12 users (show)

Fixed In Version: gcc-12.0.1-0.6.fc36
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-02-06 18:11:47 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
preprocessed source (41.19 KB, text/plain)
2022-02-04 09:42 UTC, Mamoru TASAKA
no flags Details


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 104380 0 P3 RESOLVED -D_FORTIFY_SOURCE -mabi=ieeelongdouble -std=c* wrong-code 2022-02-12 12:51:40 UTC

Description Mamoru TASAKA 2022-02-04 09:42:21 UTC
Created attachment 1859018 [details]
preprocessed source

Description of problem:
On ppc64le:

=======================================================================
[mockbuild@3a00fe7f7f694de19171916d75a4f441 h5dump]$ cat test.c
#include <stdio.h>
#include <stdarg.h>

static char buf[4096];
static char gfmt[] = "%Lg";

static int __attribute__ ((noinline)) 
foo(char *str, const char *fmt, ...) {
	int ret;
	va_list ap;
	va_start(ap, fmt);
	ret = vsnprintf(str, 4096, fmt, ap);
	va_end(ap);
	return ret;
}

int main(void) {
	long double dval = 128;
	int ret = foo(buf, gfmt, dval);

	fprintf(stdout, "ret[%d]\n", ret);
	fprintf(stdout, "buf[%s]\n", buf);

	return 0;
}
[mockbuild@3a00fe7f7f694de19171916d75a4f441 h5dump]$ gcc -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L   -DNDEBUG -UH5_DEBUG_API -I../../../src  -std=c99  -Wall -Wcast-qual -Wconversion -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-include-dirs -Wno-c++-compat -Wno-format-nonliteral -Wshadow -Wundef -Wwrite-strings -pedantic -Wlarger-than=2560 -Wlogical-op -Wframe-larger-than=16384 -Wpacked-bitfield-compat -Wsync-nand -Wstrict-overflow=5 -Wno-unsuffixed-float-constants -Wdouble-promotion -Wtrampolines -Wstack-usage=8192 -Wmaybe-uninitialized -Wdate-time -Warray-bounds=2 -Wc99-c11-compat -Wduplicated-cond -Whsa -Wnormalized -Wnull-dereference -Wunused-const-variable -Walloca -Walloc-zero -Wduplicated-branches -Wformat-overflow=2 -Wformat-truncation=1 -Wrestrict -Wattribute-alias -Wcast-align=strict -Wshift-overflow=2 -Wattribute-alias=2 -Wmissing-profile -Wc11-c2x-compat -fstdarg-opt -fdiagnostics-urls=never -fno-diagnostics-color -s -Wno-aggregate-return -Wno-inline -Wno-missing-format-attribute -Wno-missing-noreturn -Wno-overlength-strings -Wno-jump-misses-init -Wno-suggest-attribute=const -Wno-suggest-attribute=noreturn -Wno-suggest-attribute=pure -Wno-suggest-attribute=format -Wno-suggest-attribute=cold -Wno-suggest-attribute=malloc  -Wbad-function-cast -Wimplicit-function-declaration -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpacked -Wpointer-sign -Wpointer-to-int-cast -Wredundant-decls -Wstrict-prototypes -Wswitch -Wunused-function -Wunused-variable -Wunused-parameter -Wcast-align -Wunused-but-set-variable -Wformat -Wincompatible-pointer-types -Wshadow -Wcast-function-type -Wmaybe-uninitialized -O3 -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -mcpu=power8 -mtune=power8 -fasynchronous-unwind-tables -fstack-clash-protection -o testfoo test.c && ./testfoo
test.c:4:13: warning: size of 'buf' 4096 bytes exceeds maximum object size 2560 [-Wlarger-than=]
    4 | static char buf[4096];
      |             ^~~
ret[1]
buf[0]
=======================================================================


Apparently the result is not okay, with -O0:
ret[3]
buf[128]


Version-Release number of selected component (if applicable):
gcc-12.0.1-0.4.fc36.ppc64le

How reproducible:
100%

Comment 1 Tulio Magno Quites Machado Filho 2022-02-04 17:52:58 UTC
The problem seems to be in glibc.

I reduced the compiler call to gcc -std=c99  -O1  -Wp,-D_FORTIFY_SOURCE=2 -o test test.c && ./test

Comment 2 Jakub Jelinek 2022-02-04 17:54:52 UTC
I've already fixed it in gcc.

Comment 3 Fedora Update System 2022-02-06 17:40:13 UTC
FEDORA-2022-fba9d09417 has been submitted as an update to Fedora 36. https://bodhi.fedoraproject.org/updates/FEDORA-2022-fba9d09417

Comment 4 Fedora Update System 2022-02-06 18:11:47 UTC
FEDORA-2022-fba9d09417 has been pushed to the Fedora 36 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.