<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 parsing of floating-point constants is locale-dependent"
   href="https://llvm.org/bugs/show_bug.cgi?id=25788">25788</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>IR parsing of floating-point constants is locale-dependent
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.6
          </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>LLVM assembly language parser
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>pitrou@free.fr
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Parsing of floating-point constants in decimal notation is locale-dependent.
With a locale other than C, a bogus value may be emitted.  This was observed
with LLVM 3.6 but inspection of trunk suggests the issue hasn't been corrected,
as it seems due to the use of std::atof() in lib/AsmParser/LLLexer.cpp.

Not only atof() is locale-dependent, but it's quite lenient. So if for instance
you pass it "1.23e+01" and the current locale has the comma (",") as decimal
separator, atof() simply ignores the invalid trailing characters and returns
1.0.

I have a small reproducer using the llvmlite bindings below (I don't seem to be
able to reproduce using the LLVM command-line tools, perhaps because they force
the locale to "C"). It parses the IR and prints out the IR of the parsed
module:

```
import locale

import llvmlite.binding as llvm

ir = """
    define double @func()
    {
        ret double 1.23e+01
    }
    """

locale.setlocale(locale.LC_ALL, ("fr_FR", "UTF-8"))

llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()

mod = llvm.parse_assembly(ir)
print(mod)  # => the printed assembly returns 1.0, not 12.3...
```

Probably a similar reproducer can be written using the C++ API.</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>