<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - IR change avoids clue to the compiler optimization that the global variable is not referred from other external obj files"
   href="https://bugs.llvm.org/show_bug.cgi?id=41978">41978</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>IR change avoids clue to the compiler optimization that the global variable is not referred from other external obj files
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>balarishi.bhogadi@amd.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre><span class="quote">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>></span >

Problem Module: lld
-----------------------

Test Case:
-------------


#include <stdio.h>  
#include <stdlib.h>  

// A linked list node  
struct Node {  
    int data;  
    struct Node* next;  
    struct Node* prev;  
};  

/* Given a reference (pointer to pointer) to the head of a list  
and an int, inserts a new node on the front of the list. */
void push(struct Node** head_ref, int new_data)  
{  
    struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));  

    new_node->data = new_data;  

    new_node->next = (*head_ref);  
    new_node->prev = NULL;  

    if ((*head_ref) != NULL)  
        (*head_ref)->prev = new_node;  

    (*head_ref) = new_node;  
}  


// This function prints contents of linked list starting from the given node  
void printList(void);  

struct Node* head;


/* Driver program to test above functions*/
int main()  
{  

    head = NULL;
    push(&head, 7);  
    push(&head, 1);  
    push(&head, 4);  

    printList1(head);  

    return 0;  



Compiler invocation: clang -flto -fuse-ld=lld -O3 t3.c -o a.out


Symptoms of issue:
------------------

When the IR for the above code was dumped during  FLTO stage prior to May12th
2019 (in llvm compiler) the IR (for head global variable) was as follows,

@head = internal global %struct.Node* null, align 8

After May12th or later the IR (for head global variable) looked as follows,

@head = common dso_local global %struct.Node* null, align 8

This change does not seem to be appropriate since it does not give clue to the
compiler optimization that the global variable is not referred from other
external obj files.



Probable checkin:
----------------------

Author: Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>>
Date:   Thu May 16 03:29:03 2019 +0000

    Introduce CommonSymbol.

Not sure if this checkin is the place where this issue got introduced.

<span class="quote">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>></span ></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>