<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 - Changing behavior in clang::SourceRange.getEnd() between clang versions 8 and 9 and later"
href="https://bugs.llvm.org/show_bug.cgi?id=45790">45790</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Changing behavior in clang::SourceRange.getEnd() between clang versions 8 and 9 and later
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>9.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>FreeBSD
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>lunkov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=23439" name="attach_23439" title="Test file">attachment 23439</a> <a href="attachment.cgi?id=23439&action=edit" title="Test file">[details]</a></span>
Test file
I encountered a backward compatibility violation in the
clang::SourceRange.getEnd() between versions 8 and 9 in the following code:
------
void MyPPCallbacks::If(SourceLocation Loc, SourceRange ConditionRange,
ConditionValueKind ConditionValue){
[...]
StartPos = SM.getFileOffset(SM.getFileLoc(Loc));
EndPos = SM.getFileOffset(SM.getFileLoc(ConditionRange.getEnd()));
[...]
}
------
This code has worked without changing behavior since clang version 3.4.
In clang version 8.0, EndPos is ALWAYS equal to the position of the macro
character following the last, and in clang version 9.0 and later EndPos takes
on a value depending on the expression.
In the following example, you can see the difference which values EndPos takes
in various expressions in clang 8 and clang 9:
------
#define TEST_MACRO 1
// example 1
#if defined(TEST_MACRO) && !defined(UNDEF_TEST_MACRO)
// ^ clang 8
ConditionRange.getEnd().getRawEncoding() = 91
// ^ clang 9
ConditionRange.getEnd().getRawEncoding() = 90
#endif
// example 2
#if TEST_MACRO && TEST_MACRO
// ^ clang 8
ConditionRange.getEnd().getRawEncoding() = 364
// ^ clang 9 ConditionRange.getEnd().getRawEncoding() =
2147495546
#endif
// example 3
#if TEST_MACRO
// ^ clang 8 ConditionRange.getEnd().getRawEncoding() = 572
// ^ clang 9 ConditionRange.getEnd().getRawEncoding() = 2147495548
#endif
int main(){ return 0; }
------
In examples 2 and 3, the value of getRawEncoding() for some reason changes
depending on the length of the file.</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>