Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • G gcc
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 39
    • Merge requests 39
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gcc-mirror
  • gcc
  • Merge requests
  • !30

GCC 7.3.0 optimization bug

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge gcc-7-branch into master Sep 06, 2018
  • Overview 1
  • Commits 1672
  • Pipelines 0
  • Changes 421+

Created by: CoZZmOnAvT

Interesting bug with compilator optimization. Code written in C. gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3) gcc -g3 -Wextra -Werror -Wall -O2 -fdata-sections -ffunction-sections

else
{
    err = "Some string";
    ft_dlstpush(&list, ft_dlstnew(some_ptr, sizeof(void *)));
}

list - It's a simple storage for pointers, this storage circulary double-linked, so it has root, empty node without data.

if this block is written as:

else if ((err = "Some string"))
    ft_dlstpush(&list, ft_dlstnew(some_ptr, sizeof(void *)));

No leak detected.

This is the structure of list node.

typedef struct           s_dlist
{
	struct s_dlist    *prev;
	void              *content;
	size_t            content_size;
	struct s_dlist    *next;
}                        t_dlist;
void	ft_dlstpush(t_dlist **dest, t_dlist *src)
{
	if (!dest || !src)
		return ;
	!*dest ? *dest = ft_dlstnew(NULL, 0) : 0;
	(*dest)->next->prev = src;
	src->next = (*dest)->next;
	src->prev = *dest;
	(*dest)->next = src;
}
t_dlist		*ft_dlstnew(void *content, size_t content_size)
{
	t_dlist	*new;

	if (!(new = malloc(sizeof(t_dlist))))
		return (NULL);
	new->prev = new;
	new->next = new;
	new->content = content;
	new->content_size = content ? content_size : 0;
	return (new);
}

Disassembling two object binaries (with optimization and without) gives no difference.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: gcc-7-branch