<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 - When compiling for arch armv6kz, __ARM_FEATURE_LDREX predefined incorrectly"
   href="https://bugs.llvm.org/show_bug.cgi?id=38553">38553</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>When compiling for arch armv6kz, __ARM_FEATURE_LDREX predefined incorrectly
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>Driver
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>sethml@ofb.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When compiling with arch armv6kz, __ARM_FEATURE_LDREX is predefined to 0x4,
while when compiling for armv6k it's predefined to 0xf:

% clang++ -E -dM --target=arm-linux-gnueabihf -march=armv6kz - </dev/null |
grep LDREX
#define __ARM_FEATURE_LDREX 0x4
% clang++ -E -dM --target=arm-linux-gnueabihf -march=armv6k - </dev/null | grep
LDREX
#define __ARM_FEATURE_LDREX 0xf

According to ARM's document "ARMĀ® C Language Extensions Release 2.0":

 
<a href="http://infocenter.arm.com/help/topic/com.arm.doc.ihi0053c/IHI0053C_acle_2_0.pdf">http://infocenter.arm.com/help/topic/com.arm.doc.ihi0053c/IHI0053C_acle_2_0.pdf</a>

  The following values of __ARM_FEATURE_LDREX may occur:
  Macro value | Access widths                    | Example architecture
  (undefined) | none                             | ARM v5, ARM v6-M
  0x04        | word                             | ARM v6
  0x07        | word, halfword, byte             | ARM v7-M
  0x0F        | doubleword, word, halfword, byte | ARM v6K, ARM v7-A/R

The "armv6kz" architecture is a synonym for "armv6z" and "armv6zk". It's the
architecture implemented by the ARM1176JZF-S CPU which is used in all older
Raspberry Pis, so it's a surprisingly common architecture. It's a bit hard to
find an authoritative reference in ARM's documentation, but armv6kz is a
superset of armv6k. The "ARMĀ® Architecture Reference Manual ARMv7-A and ARMv7-R
edition" on page 1156 says:
 
<a href="https://static.docs.arm.com/ddi0406/c/DDI0406C_C_arm_architecture_reference_manual.pdf">https://static.docs.arm.com/ddi0406/c/DDI0406C_C_arm_architecture_reference_manual.pdf</a>

  Note:
  The Security Extensions are also permitted as an extension to the ARMv6K 
  architecture. The resulting combination is sometimes called the ARMv6Z or
ARMv6KZ 
  architecture.

As such, on this architecture __ARM_FEATURE_LDREX should be defined to 0xf.

I'm not in a position to test and submit a patch, but I think the fix is
simple. In lib/Basic/Targets/ARM.cpp ARMTargetInfo::handleTargetFeatures(),
change:
    else if (ArchKind == llvm::ARM::ArchKind::ARMV6K)
      LDREX = LDREX_D | LDREX_W | LDREX_H | LDREX_B;
to:
    else if (ArchKind == llvm::ARM::ArchKind::ARMV6K ||
             ArchKind == llvm::ARM::ArchKind::ARMV6KZ)
      LDREX = LDREX_D | LDREX_W | LDREX_H | LDREX_B;</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>