[clang] 42fa5ba - [clang][preprocessor] Add more macros to target AVR

Ben Shi via cfe-commits cfe-commits at lists.llvm.org
Sun May 1 21:39:09 PDT 2022


Author: Ben Shi
Date: 2022-05-02T04:37:57Z
New Revision: 42fa5bae7afcd58f769adfd46d15996eeb0381ad

URL: https://github.com/llvm/llvm-project/commit/42fa5bae7afcd58f769adfd46d15996eeb0381ad
DIFF: https://github.com/llvm/llvm-project/commit/42fa5bae7afcd58f769adfd46d15996eeb0381ad.diff

LOG: [clang][preprocessor] Add more macros to target AVR

Reviewed By: MaskRay, aykevl

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

Added: 
    

Modified: 
    clang/lib/Basic/Targets/AVR.cpp
    clang/test/Preprocessor/avr-common.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index 14b3d0497c62c..7be33d4424f4d 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -384,6 +384,9 @@ void AVRTargetInfo::getTargetDefines(const LangOptions &Opts,
     auto It = llvm::find_if(
         AVRMcus, [&](const MCUInfo &Info) { return Info.Name == this->CPU; });
 
+    if (It->IsTiny)
+      Builder.defineMacro("__AVR_TINY__", "1");
+
     if (It != std::end(AVRMcus)) {
       Builder.defineMacro(It->DefineName);
       if (It->NumFlashBanks >= 1)

diff  --git a/clang/test/Preprocessor/avr-common.c b/clang/test/Preprocessor/avr-common.c
index 8a03c1d91ab56..979dc52e67a10 100644
--- a/clang/test/Preprocessor/avr-common.c
+++ b/clang/test/Preprocessor/avr-common.c
@@ -1,6 +1,11 @@
-// RUN: %clang_cc1 -E -dM -triple avr-unknown-unknown /dev/null | FileCheck -match-full-lines %s
+// RUN: %clang_cc1 -E -dM -triple avr-unknown-unknown -target-cpu attiny13 /dev/null | FileCheck -match-full-lines --check-prefixes=CHECK,AVR %s
+// RUN: %clang_cc1 -E -dM -triple avr-unknown-unknown -target-cpu attiny4 /dev/null | FileCheck -match-full-lines --check-prefixes=CHECK,TINY %s
 
 // CHECK: #define AVR 1
 // CHECK: #define __AVR 1
+
+// TINY: #define __AVR_TINY__ 1
+// AVR-NOT: __AVR_TINY__
+
 // CHECK: #define __AVR__ 1
 // CHECK: #define __ELF__ 1


        


More information about the cfe-commits mailing list