[clang] 334ac81 - Fix the check for regparm in FunctionType::ExtInfo

Momchil Velikov via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 27 08:01:42 PDT 2020


Author: Momchil Velikov
Date: 2020-04-27T16:01:07+01:00
New Revision: 334ac81054018c3ae6058a0bf12e9c9363bd50ad

URL: https://github.com/llvm/llvm-project/commit/334ac81054018c3ae6058a0bf12e9c9363bd50ad
DIFF: https://github.com/llvm/llvm-project/commit/334ac81054018c3ae6058a0bf12e9c9363bd50ad.diff

LOG: Fix the check for regparm in FunctionType::ExtInfo

`getHasRegParm()` was working under the assumption that the RegParm
bits are the last field, which is no longer true, after adding the
`NoCfCheck` and `CmseNSCall` fields.

This causes a spurious "regparm 0" attribute to appear when a function
type is declared with either `__attribute__((nocf_check))` or
`__attribute__((cmse_nonsecure_call))`.

Differential Revision: https://reviews.llvm.org/D77270

Added: 
    clang/test/AST/spurious-regparm.c

Modified: 
    clang/include/clang/AST/Type.h

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index cf746d9b947a..08522a670c99 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3518,13 +3518,12 @@ class FunctionType : public Type {
     enum { NoReturnMask = 0x20 };
     enum { ProducesResultMask = 0x40 };
     enum { NoCallerSavedRegsMask = 0x80 };
-    enum { NoCfCheckMask = 0x800 };
-    enum { CmseNSCallMask = 0x1000 };
     enum {
-      RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask |
-                      NoCallerSavedRegsMask | NoCfCheckMask | CmseNSCallMask),
+      RegParmMask =  0x700,
       RegParmOffset = 8
-    }; // Assumed to be the last field
+    };
+    enum { NoCfCheckMask = 0x800 };
+    enum { CmseNSCallMask = 0x1000 };
     uint16_t Bits = CC_C;
 
     ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
@@ -3557,7 +3556,7 @@ class FunctionType : public Type {
     bool getCmseNSCall() const { return Bits & CmseNSCallMask; }
     bool getNoCallerSavedRegs() const { return Bits & NoCallerSavedRegsMask; }
     bool getNoCfCheck() const { return Bits & NoCfCheckMask; }
-    bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; }
+    bool getHasRegParm() const { return ((Bits & RegParmMask) >> RegParmOffset) != 0; }
 
     unsigned getRegParm() const {
       unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;

diff  --git a/clang/test/AST/spurious-regparm.c b/clang/test/AST/spurious-regparm.c
new file mode 100644
index 000000000000..4ae23f017241
--- /dev/null
+++ b/clang/test/AST/spurious-regparm.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple armv8.1m.main-eabi -mcmse -fsyntax-only %s -ast-dump | FileCheck %s
+// REQUIRES: arm-registered-target
+typedef int (*fn_t)(int) __attribute__((cmse_nonsecure_call));
+// CHECK-NOT: regparm 0


        


More information about the cfe-commits mailing list