[clang] cfc0027 - [AVR] Support aliases in non-zero address space

2020-04-13 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2020-04-14T00:42:19+02:00
New Revision: cfc002714a208bdbc51fade56141a38fbba26e24

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

LOG: [AVR] Support aliases in non-zero address space

This fixes code like the following on AVR:

void foo(void) {
}
void bar(void) __attribute__((alias("foo")));

Code like this is present in compiler-rt, which I'm trying to build.

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

Added: 
clang/test/CodeGen/alias-avr.c

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8b7d52b88146..0f56dcb3e26c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4536,8 +4536,9 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) {
   }
 
   // Create the new alias itself, but don't set a name yet.
+  unsigned AS = Aliasee->getType()->getPointerAddressSpace();
   auto *GA =
-  llvm::GlobalAlias::create(DeclTy, 0, LT, "", Aliasee, &getModule());
+  llvm::GlobalAlias::create(DeclTy, AS, LT, "", Aliasee, &getModule());
 
   if (Entry) {
 if (GA->getAliasee() == Entry) {

diff  --git a/clang/test/CodeGen/alias-avr.c b/clang/test/CodeGen/alias-avr.c
new file mode 100644
index ..dfec154beb34
--- /dev/null
+++ b/clang/test/CodeGen/alias-avr.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck 
%s
+
+int mul(int a, int b) {
+   return a * b;
+}
+
+// CHECK: @multiply = alias i16 (i16, i16), i16 (i16, i16) addrspace(1)* @mul
+int multiply(int x, int y) __attribute__((alias("mul")));



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fe06e23 - [AVR] Define __ELF__

2020-04-14 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2020-04-15T00:22:53+02:00
New Revision: fe06e231ff1536e7d0a99551590f6de5a38ce23a

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

LOG: [AVR] Define __ELF__

This symbol is defined in avr-gcc. Because AVR normally uses the ELF
format, define the symbol unconditionally.

This patch is needed to get Clang to compile compiler-rt.

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

Added: 


Modified: 
clang/lib/Basic/Targets/AVR.cpp
clang/test/CodeGen/avr/target-cpu-defines/atmega328p.c
clang/test/CodeGen/avr/target-cpu-defines/attiny104.c
clang/test/CodeGen/avr/target-cpu-defines/common.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index d865676700b5..bb215b4114ac 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -300,6 +300,7 @@ void AVRTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   Builder.defineMacro("AVR");
   Builder.defineMacro("__AVR");
   Builder.defineMacro("__AVR__");
+  Builder.defineMacro("__ELF__");
 
   if (!this->CPU.empty()) {
 auto It = llvm::find_if(

diff  --git a/clang/test/CodeGen/avr/target-cpu-defines/atmega328p.c 
b/clang/test/CodeGen/avr/target-cpu-defines/atmega328p.c
index 83b0accbb93f..29f8fa6325ec 100644
--- a/clang/test/CodeGen/avr/target-cpu-defines/atmega328p.c
+++ b/clang/test/CodeGen/avr/target-cpu-defines/atmega328p.c
@@ -5,3 +5,4 @@
 // CHECK: #define __AVR 1
 // CHECK: #define __AVR_ATmega328P__ 1
 // CHECK: #define __AVR__ 1
+// CHECK: #define __ELF__ 1

diff  --git a/clang/test/CodeGen/avr/target-cpu-defines/attiny104.c 
b/clang/test/CodeGen/avr/target-cpu-defines/attiny104.c
index 7de65bf09ba3..3f3d8714591e 100644
--- a/clang/test/CodeGen/avr/target-cpu-defines/attiny104.c
+++ b/clang/test/CodeGen/avr/target-cpu-defines/attiny104.c
@@ -5,3 +5,4 @@
 // CHECK: #define __AVR 1
 // CHECK: #define __AVR_ATtiny104__ 1
 // CHECK: #define __AVR__ 1
+// CHECK: #define __ELF__ 1

diff  --git a/clang/test/CodeGen/avr/target-cpu-defines/common.c 
b/clang/test/CodeGen/avr/target-cpu-defines/common.c
index 0b11f5dbdd59..3f938522e7eb 100644
--- a/clang/test/CodeGen/avr/target-cpu-defines/common.c
+++ b/clang/test/CodeGen/avr/target-cpu-defines/common.c
@@ -4,3 +4,4 @@
 // CHECK: #define AVR 1
 // CHECK: #define __AVR 1
 // CHECK: #define __AVR__ 1
+// CHECK: #define __ELF__ 1



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 215dc2e - [AVR] Use the correct address space for non-prototyped function calls

2020-04-15 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2020-04-15T23:44:51+02:00
New Revision: 215dc2e203341f7d1edc4c4a191b048af4ace43d

URL: 
https://github.com/llvm/llvm-project/commit/215dc2e203341f7d1edc4c4a191b048af4ace43d
DIFF: 
https://github.com/llvm/llvm-project/commit/215dc2e203341f7d1edc4c4a191b048af4ace43d.diff

LOG: [AVR] Use the correct address space for non-prototyped function calls

Some function declarations like this:

void foo();

do not have a type declaration, for that you'd use:

void foo(void);

Clang internally bitcasts the variadic function declaration to a
function pointer, but doesn't use the correct address space on AVR. This
commit fixes that.

This fix is necessary to let Clang compile compiler-rt for AVR.

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

Added: 
clang/test/CodeGen/address-space-avr.c

Modified: 
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index eca76f36eda8..85c2d318c196 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5063,7 +5063,8 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, 
const CGCallee &OrigCallee
   // to the function type.
   if (isa(FnType) || Chain) {
 llvm::Type *CalleeTy = getTypes().GetFunctionType(FnInfo);
-CalleeTy = CalleeTy->getPointerTo();
+int AS = Callee.getFunctionPointer()->getType()->getPointerAddressSpace();
+CalleeTy = CalleeTy->getPointerTo(AS);
 
 llvm::Value *CalleePtr = Callee.getFunctionPointer();
 CalleePtr = Builder.CreateBitCast(CalleePtr, CalleeTy, "callee.knr.cast");

diff  --git a/clang/test/CodeGen/address-space-avr.c 
b/clang/test/CodeGen/address-space-avr.c
new file mode 100644
index ..58518e5e3453
--- /dev/null
+++ b/clang/test/CodeGen/address-space-avr.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple avr -emit-llvm < %s | FileCheck %s
+
+// Test that function declarations in nonzero address spaces without prototype
+// are called correctly.
+
+// CHECK: define void @bar() addrspace(1)
+// CHECK: call addrspace(1) void bitcast (void (...) addrspace(1)* @foo to 
void (i16) addrspace(1)*)(i16 3)
+// CHECK: declare void @foo(...) addrspace(1)
+void foo();
+void bar(void) {
+   foo(3);
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ceba881 - [AVR][NFC] Move preprocessor tests to Preprocessor directory

2020-04-25 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2020-04-26T01:29:25+02:00
New Revision: ceba881aeac1e24dcffb1eecdc6507c0701f6865

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

LOG: [AVR][NFC] Move preprocessor tests to Preprocessor directory

These tests were placed in the CodeGen directory while they really
should have been placed in the Preprocessor directory.

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

Added: 
clang/test/Preprocessor/avr-atmega328p.c
clang/test/Preprocessor/avr-attiny104.c
clang/test/Preprocessor/avr-common.c

Modified: 


Removed: 
clang/test/CodeGen/avr/target-cpu-defines/atmega328p.c
clang/test/CodeGen/avr/target-cpu-defines/attiny104.c
clang/test/CodeGen/avr/target-cpu-defines/common.c



diff  --git a/clang/test/CodeGen/avr/target-cpu-defines/atmega328p.c 
b/clang/test/Preprocessor/avr-atmega328p.c
similarity index 88%
rename from clang/test/CodeGen/avr/target-cpu-defines/atmega328p.c
rename to clang/test/Preprocessor/avr-atmega328p.c
index 29f8fa6325ec..78db00ac9243 100644
--- a/clang/test/CodeGen/avr/target-cpu-defines/atmega328p.c
+++ b/clang/test/Preprocessor/avr-atmega328p.c
@@ -1,4 +1,3 @@
-// REQUIRES: avr-registered-target
 // RUN: %clang_cc1 -E -dM -triple avr-unknown-unknown -target-cpu atmega328p 
/dev/null | FileCheck -match-full-lines %s
 
 // CHECK: #define AVR 1

diff  --git a/clang/test/CodeGen/avr/target-cpu-defines/attiny104.c 
b/clang/test/Preprocessor/avr-attiny104.c
similarity index 88%
rename from clang/test/CodeGen/avr/target-cpu-defines/attiny104.c
rename to clang/test/Preprocessor/avr-attiny104.c
index 3f3d8714591e..29caffaeb3b8 100644
--- a/clang/test/CodeGen/avr/target-cpu-defines/attiny104.c
+++ b/clang/test/Preprocessor/avr-attiny104.c
@@ -1,4 +1,3 @@
-// REQUIRES: avr-registered-target
 // RUN: %clang_cc1 -E -dM -triple avr-unknown-unknown -target-cpu attiny104 
/dev/null | FileCheck -match-full-lines %s
 
 // CHECK: #define AVR 1

diff  --git a/clang/test/CodeGen/avr/target-cpu-defines/common.c 
b/clang/test/Preprocessor/avr-common.c
similarity index 85%
rename from clang/test/CodeGen/avr/target-cpu-defines/common.c
rename to clang/test/Preprocessor/avr-common.c
index 3f938522e7eb..8a03c1d91ab5 100644
--- a/clang/test/CodeGen/avr/target-cpu-defines/common.c
+++ b/clang/test/Preprocessor/avr-common.c
@@ -1,4 +1,3 @@
-// REQUIRES: avr-registered-target
 // RUN: %clang_cc1 -E -dM -triple avr-unknown-unknown /dev/null | FileCheck 
-match-full-lines %s
 
 // CHECK: #define AVR 1



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2325157 - [Clang] Move assembler into a separate file

2021-01-23 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2021-01-23T14:34:23+01:00
New Revision: 2325157c0568ffd16f3318ad54f947e4e2109ef6

URL: 
https://github.com/llvm/llvm-project/commit/2325157c0568ffd16f3318ad54f947e4e2109ef6
DIFF: 
https://github.com/llvm/llvm-project/commit/2325157c0568ffd16f3318ad54f947e4e2109ef6.diff

LOG: [Clang] Move assembler into a separate file

This change adds an AssemblerInvocation class, similar to the
CompilerInvocation class. It can be used to invoke cc1as directly.

The project I'm working on wants to compile Clang and use it as a static
library. For that to work, there must be a way to invoke the assembler
programmatically, using the same arguments as you would otherwise pass
to cc1as.

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

Added: 
clang/include/clang/Frontend/AssemblerInvocation.h
clang/lib/Frontend/AssemblerInvocation.cpp

Modified: 
clang/lib/Frontend/CMakeLists.txt
clang/tools/driver/cc1as_main.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/AssemblerInvocation.h 
b/clang/include/clang/Frontend/AssemblerInvocation.h
new file mode 100644
index ..8644f6c14228
--- /dev/null
+++ b/clang/include/clang/Frontend/AssemblerInvocation.h
@@ -0,0 +1,126 @@
+//===- AssemblerInvocation.h - Assembler Invocation Helper Data -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_FRONTEND_ASSEMBLERINVOCATION_H
+#define LLVM_CLANG_FRONTEND_ASSEMBLERINVOCATION_H
+
+#include "llvm/MC/MCTargetOptions.h"
+
+namespace clang {
+
+/// Helper class for representing a single invocation of the assembler.
+struct AssemblerInvocation {
+  /// @name Target Options
+  /// @{
+
+  /// The name of the target triple to assemble for.
+  std::string Triple;
+
+  /// If given, the name of the target CPU to determine which instructions
+  /// are legal.
+  std::string CPU;
+
+  /// The list of target specific features to enable or disable -- this should
+  /// be a list of strings starting with '+' or '-'.
+  std::vector Features;
+
+  /// The list of symbol definitions.
+  std::vector SymbolDefs;
+
+  /// @}
+  /// @name Language Options
+  /// @{
+
+  std::vector IncludePaths;
+  unsigned NoInitialTextSection : 1;
+  unsigned SaveTemporaryLabels : 1;
+  unsigned GenDwarfForAssembly : 1;
+  unsigned RelaxELFRelocations : 1;
+  unsigned DwarfVersion;
+  std::string DwarfDebugFlags;
+  std::string DwarfDebugProducer;
+  std::string DebugCompilationDir;
+  std::map DebugPrefixMap;
+  llvm::DebugCompressionType CompressDebugSections =
+  llvm::DebugCompressionType::None;
+  std::string MainFileName;
+  std::string SplitDwarfOutput;
+
+  /// @}
+  /// @name Frontend Options
+  /// @{
+
+  std::string InputFile;
+  std::vector LLVMArgs;
+  std::string OutputPath;
+  enum FileType {
+FT_Asm,  ///< Assembly (.s) output, transliterate mode.
+FT_Null, ///< No output, for timing purposes.
+FT_Obj   ///< Object file output.
+  };
+  FileType OutputType;
+  unsigned ShowHelp : 1;
+  unsigned ShowVersion : 1;
+
+  /// @}
+  /// @name Transliterate Options
+  /// @{
+
+  unsigned OutputAsmVariant;
+  unsigned ShowEncoding : 1;
+  unsigned ShowInst : 1;
+
+  /// @}
+  /// @name Assembler Options
+  /// @{
+
+  unsigned RelaxAll : 1;
+  unsigned NoExecStack : 1;
+  unsigned FatalWarnings : 1;
+  unsigned NoWarn : 1;
+  unsigned IncrementalLinkerCompatible : 1;
+  unsigned EmbedBitcode : 1;
+
+  /// The name of the relocation model to use.
+  std::string RelocationModel;
+
+  /// The ABI targeted by the backend. Specified using -target-abi. Empty
+  /// otherwise.
+  std::string TargetABI;
+
+  /// @}
+
+public:
+  AssemblerInvocation() {
+Triple = "";
+NoInitialTextSection = 0;
+InputFile = "-";
+OutputPath = "-";
+OutputType = FT_Asm;
+OutputAsmVariant = 0;
+ShowInst = 0;
+ShowEncoding = 0;
+RelaxAll = 0;
+NoExecStack = 0;
+FatalWarnings = 0;
+NoWarn = 0;
+IncrementalLinkerCompatible = 0;
+DwarfVersion = 0;
+EmbedBitcode = 0;
+  }
+
+  static bool CreateFromArgs(AssemblerInvocation &Res,
+ ArrayRef Argv,
+ DiagnosticsEngine &Diags);
+};
+
+bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags);
+
+} // namespace clang
+
+#endif // LLVM_CLANG_FRONTEND_ASSEMBLERINVOCATION_H

diff  --git a/clang/lib/Frontend/AssemblerInvocation.cpp 
b/clang/lib/Frontend/AssemblerInvocation.cpp
new file mode 100644
index ..7f6944c60379
--- /dev/null
+++ b/clang/lib/Frontend/AssemblerInvocation.cpp
@@ -0,0 +1,432 @@
+//===- AssemblerInvocation.cpp 

[clang] 0057cc5 - Revert "[Clang] Move assembler into a separate file"

2021-01-23 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2021-01-23T15:04:27+01:00
New Revision: 0057cc5a215e5a26cfbd7e1707b55bf05fa9b6bf

URL: 
https://github.com/llvm/llvm-project/commit/0057cc5a215e5a26cfbd7e1707b55bf05fa9b6bf
DIFF: 
https://github.com/llvm/llvm-project/commit/0057cc5a215e5a26cfbd7e1707b55bf05fa9b6bf.diff

LOG: Revert "[Clang] Move assembler into a separate file"

This reverts commit 2325157c0568ffd16f3318ad54f947e4e2109ef6.

Unfortunately this commit produces linker errors on some builds:
http://lab.llvm.org:8011/#/builders/57/builds/3704
http://lab.llvm.org:8011/#/builders/112/builds/3216
http://lab.llvm.org:8011/#/builders/121/builds/3900

Added: 


Modified: 
clang/lib/Frontend/CMakeLists.txt
clang/tools/driver/cc1as_main.cpp

Removed: 
clang/include/clang/Frontend/AssemblerInvocation.h
clang/lib/Frontend/AssemblerInvocation.cpp



diff  --git a/clang/include/clang/Frontend/AssemblerInvocation.h 
b/clang/include/clang/Frontend/AssemblerInvocation.h
deleted file mode 100644
index 8644f6c14228..
--- a/clang/include/clang/Frontend/AssemblerInvocation.h
+++ /dev/null
@@ -1,126 +0,0 @@
-//===- AssemblerInvocation.h - Assembler Invocation Helper Data -*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef LLVM_CLANG_FRONTEND_ASSEMBLERINVOCATION_H
-#define LLVM_CLANG_FRONTEND_ASSEMBLERINVOCATION_H
-
-#include "llvm/MC/MCTargetOptions.h"
-
-namespace clang {
-
-/// Helper class for representing a single invocation of the assembler.
-struct AssemblerInvocation {
-  /// @name Target Options
-  /// @{
-
-  /// The name of the target triple to assemble for.
-  std::string Triple;
-
-  /// If given, the name of the target CPU to determine which instructions
-  /// are legal.
-  std::string CPU;
-
-  /// The list of target specific features to enable or disable -- this should
-  /// be a list of strings starting with '+' or '-'.
-  std::vector Features;
-
-  /// The list of symbol definitions.
-  std::vector SymbolDefs;
-
-  /// @}
-  /// @name Language Options
-  /// @{
-
-  std::vector IncludePaths;
-  unsigned NoInitialTextSection : 1;
-  unsigned SaveTemporaryLabels : 1;
-  unsigned GenDwarfForAssembly : 1;
-  unsigned RelaxELFRelocations : 1;
-  unsigned DwarfVersion;
-  std::string DwarfDebugFlags;
-  std::string DwarfDebugProducer;
-  std::string DebugCompilationDir;
-  std::map DebugPrefixMap;
-  llvm::DebugCompressionType CompressDebugSections =
-  llvm::DebugCompressionType::None;
-  std::string MainFileName;
-  std::string SplitDwarfOutput;
-
-  /// @}
-  /// @name Frontend Options
-  /// @{
-
-  std::string InputFile;
-  std::vector LLVMArgs;
-  std::string OutputPath;
-  enum FileType {
-FT_Asm,  ///< Assembly (.s) output, transliterate mode.
-FT_Null, ///< No output, for timing purposes.
-FT_Obj   ///< Object file output.
-  };
-  FileType OutputType;
-  unsigned ShowHelp : 1;
-  unsigned ShowVersion : 1;
-
-  /// @}
-  /// @name Transliterate Options
-  /// @{
-
-  unsigned OutputAsmVariant;
-  unsigned ShowEncoding : 1;
-  unsigned ShowInst : 1;
-
-  /// @}
-  /// @name Assembler Options
-  /// @{
-
-  unsigned RelaxAll : 1;
-  unsigned NoExecStack : 1;
-  unsigned FatalWarnings : 1;
-  unsigned NoWarn : 1;
-  unsigned IncrementalLinkerCompatible : 1;
-  unsigned EmbedBitcode : 1;
-
-  /// The name of the relocation model to use.
-  std::string RelocationModel;
-
-  /// The ABI targeted by the backend. Specified using -target-abi. Empty
-  /// otherwise.
-  std::string TargetABI;
-
-  /// @}
-
-public:
-  AssemblerInvocation() {
-Triple = "";
-NoInitialTextSection = 0;
-InputFile = "-";
-OutputPath = "-";
-OutputType = FT_Asm;
-OutputAsmVariant = 0;
-ShowInst = 0;
-ShowEncoding = 0;
-RelaxAll = 0;
-NoExecStack = 0;
-FatalWarnings = 0;
-NoWarn = 0;
-IncrementalLinkerCompatible = 0;
-DwarfVersion = 0;
-EmbedBitcode = 0;
-  }
-
-  static bool CreateFromArgs(AssemblerInvocation &Res,
- ArrayRef Argv,
- DiagnosticsEngine &Diags);
-};
-
-bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags);
-
-} // namespace clang
-
-#endif // LLVM_CLANG_FRONTEND_ASSEMBLERINVOCATION_H

diff  --git a/clang/lib/Frontend/AssemblerInvocation.cpp 
b/clang/lib/Frontend/AssemblerInvocation.cpp
deleted file mode 100644
index 7f6944c60379..
--- a/clang/lib/Frontend/AssemblerInvocation.cpp
+++ /dev/null
@@ -1,432 +0,0 @@
-//===- AssemblerInvocation.cpp 
-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https

[clang] d256377 - [AVR][Clang] Move family names into MCU list

2022-11-15 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2022-11-15T15:29:37+01:00
New Revision: d2563775cd6e7b6b26d306ff233349443ef1945c

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

LOG: [AVR][Clang] Move family names into MCU list

This simplifies the code by avoiding some special cases for family names
(as opposed to device names).

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

Added: 


Modified: 
clang/lib/Basic/Targets/AVR.cpp
clang/lib/Basic/Targets/AVR.h
clang/test/Misc/target-invalid-cpu-note.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index 9855b6eca5c9..81656b81a18b 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -29,11 +29,13 @@ struct LLVM_LIBRARY_VISIBILITY MCUInfo {
 
 // NOTE: This list has been synchronized with gcc-avr 5.4.0 and avr-libc 2.0.0.
 static MCUInfo AVRMcus[] = {
+{"avr1", NULL, 0, false},
 {"at90s1200", "__AVR_AT90S1200__", 0, false},
 {"attiny11", "__AVR_ATtiny11__", 0, false},
 {"attiny12", "__AVR_ATtiny12__", 0, false},
 {"attiny15", "__AVR_ATtiny15__", 0, false},
 {"attiny28", "__AVR_ATtiny28__", 0, false},
+{"avr2", NULL, 1, false},
 {"at90s2313", "__AVR_AT90S2313__", 1, false},
 {"at90s2323", "__AVR_AT90S2323__", 1, false},
 {"at90s2333", "__AVR_AT90S2333__", 1, false},
@@ -47,6 +49,7 @@ static MCUInfo AVRMcus[] = {
 {"at90s8515", "__AVR_AT90S8515__", 1, false},
 {"at90c8534", "__AVR_AT90c8534__", 1, false},
 {"at90s8535", "__AVR_AT90S8535__", 1, false},
+{"avr25", NULL, 1, false},
 {"ata5272", "__AVR_ATA5272__", 1, false},
 {"ata6616c", "__AVR_ATA6616c__", 1, false},
 {"attiny13", "__AVR_ATtiny13__", 1, false},
@@ -76,10 +79,13 @@ static MCUInfo AVRMcus[] = {
 {"attiny48", "__AVR_ATtiny48__", 1, false},
 {"attiny88", "__AVR_ATtiny88__", 1, false},
 {"attiny828", "__AVR_ATtiny828__", 1, false},
+{"avr3", NULL, 1, false},
 {"at43usb355", "__AVR_AT43USB355__", 1, false},
 {"at76c711", "__AVR_AT76C711__", 1, false},
+{"avr31", NULL, 1, false},
 {"atmega103", "__AVR_ATmega103__", 1, false},
 {"at43usb320", "__AVR_AT43USB320__", 1, false},
+{"avr35", NULL, 1, false},
 {"attiny167", "__AVR_ATtiny167__", 1, false},
 {"at90usb82", "__AVR_AT90USB82__", 1, false},
 {"at90usb162", "__AVR_AT90USB162__", 1, false},
@@ -90,6 +96,7 @@ static MCUInfo AVRMcus[] = {
 {"atmega16u2", "__AVR_ATmega16U2__", 1, false},
 {"atmega32u2", "__AVR_ATmega32U2__", 1, false},
 {"attiny1634", "__AVR_ATtiny1634__", 1, false},
+{"avr4", NULL, 1, false},
 {"atmega8", "__AVR_ATmega8__", 1, false},
 {"ata6289", "__AVR_ATA6289__", 1, false},
 {"atmega8a", "__AVR_ATmega8A__", 1, false},
@@ -115,6 +122,7 @@ static MCUInfo AVRMcus[] = {
 {"at90pwm3", "__AVR_AT90PWM3__", 1, false},
 {"at90pwm3b", "__AVR_AT90PWM3B__", 1, false},
 {"at90pwm81", "__AVR_AT90PWM81__", 1, false},
+{"avr5", NULL, 1, false},
 {"ata5702m322", "__AVR_ATA5702M322__", 1, false},
 {"ata5782", "__AVR_ATA5782__", 1, false},
 {"ata5790", "__AVR_ATA5790__", 1, false},
@@ -221,6 +229,7 @@ static MCUInfo AVRMcus[] = {
 {"at90scr100", "__AVR_AT90SCR100__", 1, false},
 {"at94k", "__AVR_AT94K__", 1, false},
 {"m3000", "__AVR_AT000__", 1, false},
+{"avr51", NULL, 2, false},
 {"atmega128", "__AVR_ATmega128__", 2, false},
 {"atmega128a", "__AVR_ATmega128A__", 2, false},
 {"atmega1280", "__AVR_ATmega1280__", 2, false},
@@ -233,10 +242,12 @@ static MCUInfo AVRMcus[] = {
 {"at90can128", "__AVR_AT90CAN128__", 2, false},
 {"at90usb1286", "__AVR_AT90USB1286__", 2, false},
 {"at90usb1287", "__AVR_AT90USB1287__", 2, false},
+{"avr6", NULL, 4, false},
 {"atmega2560", "__AVR_ATmega2560__", 4, false},
 {"atmega2561", "__AVR_ATmega2561__", 4, false},
 {"atmega256rfr2", "__AVR_ATmega256RFR2__", 4, false},
 {"atmega2564rfr2", "__AVR_ATmega2564RFR2__", 4, false},
+{"avrxmega2", NULL, 1, false},
 {"atxmega16a4", "__AVR_ATxmega16A4__", 1, false},
 {"atxmega16a4u", "__AVR_ATxmega16A4U__", 1, false},
 {"atxmega16c4", "__AVR_ATxmega16C4__", 1, false},
@@ -250,6 +261,7 @@ static MCUInfo AVRMcus[] = {
 {"atxmega32e5", "__AVR_ATxmega32E5__", 1, false},
 {"atxmega16e5", "__AVR_ATxmega16E5__", 1, false},
 {"atxmega8e5", "__AVR_ATxmega8E5__", 1, false},
+{"avrxmega4", NULL, 1, false},
 {"atxmega64a3", "__AVR_ATxmega64A3__", 1, false},
 {"atxmega64a3u", "__AVR_ATxmega64A3U__", 1, false},
 {"atxmega64a4u", "__AVR_ATxmega64A4U__", 1, false},
@@ -258,8 +270,10 @@ static MCUInfo AVRMcus[] = {
 {"atxmega64c3", "__AVR_ATxmega64C3__", 1, false},
 {"atxmega64d3", "__AVR_ATxmega64D3__", 1, f

[clang] 09ab9d4 - [AVR][Clang] Implement __AVR_ARCH__ macro

2022-11-15 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2022-11-15T15:29:37+01:00
New Revision: 09ab9d4d111f7ee2c31b7783099ca41f3aab625d

URL: 
https://github.com/llvm/llvm-project/commit/09ab9d4d111f7ee2c31b7783099ca41f3aab625d
DIFF: 
https://github.com/llvm/llvm-project/commit/09ab9d4d111f7ee2c31b7783099ca41f3aab625d.diff

LOG: [AVR][Clang] Implement __AVR_ARCH__ macro

This macro is defined in avr-gcc, and is very useful especially in
assembly code to check whether particular instructions are supported. It
is also the basis for other macros like __AVR_HAVE_ELPM__.

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

Added: 


Modified: 
clang/lib/Basic/Targets/AVR.cpp
clang/lib/Basic/Targets/AVR.h
clang/test/Preprocessor/avr-atmega328p.c
clang/test/Preprocessor/avr-attiny104.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index 81656b81a18b..e3d1c661df5a 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -23,326 +23,326 @@ namespace targets {
 struct LLVM_LIBRARY_VISIBILITY MCUInfo {
   const char *Name;
   const char *DefineName;
+  StringRef Arch; // The __AVR_ARCH__ value.
   const int NumFlashBanks; // Set to 0 for the devices do not support LPM/ELPM.
-  bool IsTiny; // Set to true for the devices belong to the avrtiny family.
 };
 
 // NOTE: This list has been synchronized with gcc-avr 5.4.0 and avr-libc 2.0.0.
 static MCUInfo AVRMcus[] = {
-{"avr1", NULL, 0, false},
-{"at90s1200", "__AVR_AT90S1200__", 0, false},
-{"attiny11", "__AVR_ATtiny11__", 0, false},
-{"attiny12", "__AVR_ATtiny12__", 0, false},
-{"attiny15", "__AVR_ATtiny15__", 0, false},
-{"attiny28", "__AVR_ATtiny28__", 0, false},
-{"avr2", NULL, 1, false},
-{"at90s2313", "__AVR_AT90S2313__", 1, false},
-{"at90s2323", "__AVR_AT90S2323__", 1, false},
-{"at90s2333", "__AVR_AT90S2333__", 1, false},
-{"at90s2343", "__AVR_AT90S2343__", 1, false},
-{"attiny22", "__AVR_ATtiny22__", 1, false},
-{"attiny26", "__AVR_ATtiny26__", 1, false},
-{"at86rf401", "__AVR_AT86RF401__", 1, false},
-{"at90s4414", "__AVR_AT90S4414__", 1, false},
-{"at90s4433", "__AVR_AT90S4433__", 1, false},
-{"at90s4434", "__AVR_AT90S4434__", 1, false},
-{"at90s8515", "__AVR_AT90S8515__", 1, false},
-{"at90c8534", "__AVR_AT90c8534__", 1, false},
-{"at90s8535", "__AVR_AT90S8535__", 1, false},
-{"avr25", NULL, 1, false},
-{"ata5272", "__AVR_ATA5272__", 1, false},
-{"ata6616c", "__AVR_ATA6616c__", 1, false},
-{"attiny13", "__AVR_ATtiny13__", 1, false},
-{"attiny13a", "__AVR_ATtiny13A__", 1, false},
-{"attiny2313", "__AVR_ATtiny2313__", 1, false},
-{"attiny2313a", "__AVR_ATtiny2313A__", 1, false},
-{"attiny24", "__AVR_ATtiny24__", 1, false},
-{"attiny24a", "__AVR_ATtiny24A__", 1, false},
-{"attiny4313", "__AVR_ATtiny4313__", 1, false},
-{"attiny44", "__AVR_ATtiny44__", 1, false},
-{"attiny44a", "__AVR_ATtiny44A__", 1, false},
-{"attiny84", "__AVR_ATtiny84__", 1, false},
-{"attiny84a", "__AVR_ATtiny84A__", 1, false},
-{"attiny25", "__AVR_ATtiny25__", 1, false},
-{"attiny45", "__AVR_ATtiny45__", 1, false},
-{"attiny85", "__AVR_ATtiny85__", 1, false},
-{"attiny261", "__AVR_ATtiny261__", 1, false},
-{"attiny261a", "__AVR_ATtiny261A__", 1, false},
-{"attiny441", "__AVR_ATtiny441__", 1, false},
-{"attiny461", "__AVR_ATtiny461__", 1, false},
-{"attiny461a", "__AVR_ATtiny461A__", 1, false},
-{"attiny841", "__AVR_ATtiny841__", 1, false},
-{"attiny861", "__AVR_ATtiny861__", 1, false},
-{"attiny861a", "__AVR_ATtiny861A__", 1, false},
-{"attiny87", "__AVR_ATtiny87__", 1, false},
-{"attiny43u", "__AVR_ATtiny43U__", 1, false},
-{"attiny48", "__AVR_ATtiny48__", 1, false},
-{"attiny88", "__AVR_ATtiny88__", 1, false},
-{"attiny828", "__AVR_ATtiny828__", 1, false},
-{"avr3", NULL, 1, false},
-{"at43usb355", "__AVR_AT43USB355__", 1, false},
-{"at76c711", "__AVR_AT76C711__", 1, false},
-{"avr31", NULL, 1, false},
-{"atmega103", "__AVR_ATmega103__", 1, false},
-{"at43usb320", "__AVR_AT43USB320__", 1, false},
-{"avr35", NULL, 1, false},
-{"attiny167", "__AVR_ATtiny167__", 1, false},
-{"at90usb82", "__AVR_AT90USB82__", 1, false},
-{"at90usb162", "__AVR_AT90USB162__", 1, false},
-{"ata5505", "__AVR_ATA5505__", 1, false},
-{"ata6617c", "__AVR_ATA6617C__", 1, false},
-{"ata664251", "__AVR_ATA664251__", 1, false},
-{"atmega8u2", "__AVR_ATmega8U2__", 1, false},
-{"atmega16u2", "__AVR_ATmega16U2__", 1, false},
-{"atmega32u2", "__AVR_ATmega32U2__", 1, false},
-{"attiny1634", "__AVR_ATtiny1634__", 1, false},
-{"avr4", NULL, 1, false},
-{"atmega8", "__AVR_ATmega8__", 1, false},
-{"ata6289", "__AVR_ATA6289__", 1, false},
-{"atmega8a", "__AVR_ATmega8A__", 1, false},
-

[clang] 75d12e4 - [libclang] Fall back to getMainExecutable when dladdr fails

2022-05-29 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2022-05-29T13:40:43+02:00
New Revision: 75d12e49c729e65f77bfdfe65b16df8c39944d35

URL: 
https://github.com/llvm/llvm-project/commit/75d12e49c729e65f77bfdfe65b16df8c39944d35
DIFF: 
https://github.com/llvm/llvm-project/commit/75d12e49c729e65f77bfdfe65b16df8c39944d35.diff

LOG: [libclang] Fall back to getMainExecutable when dladdr fails

musl-libc doesn't support dladdr in statically linked binaries:

> Are you using static or dynamic linking? If static, dladdr is just a
> stub that always fails. It could be implemented to work under some
> conditions, but it would be highly dependent on what options you
> compile the binary with, since by default static binaries do not
> contain the bloat that would be needed to perform introspection.

Source: https://www.openwall.com/lists/musl/2013/01/15/25 (in response
to a bug report).

Libclang unfortunately uses dladdr to find the ResourcesPath so will
fail if it is linked statically on Alpine Linux. This patch fixes this
issue by falling back to getMainExecutable if dladdr returns an error.

Reference: 
https://github.com/llvm/llvm-project/issues/40641#issuecomment-981011427

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

Added: 


Modified: 
clang/tools/libclang/CIndexer.cpp

Removed: 




diff  --git a/clang/tools/libclang/CIndexer.cpp 
b/clang/tools/libclang/CIndexer.cpp
index c7baab3a2c470..41f06a83553ad 100644
--- a/clang/tools/libclang/CIndexer.cpp
+++ b/clang/tools/libclang/CIndexer.cpp
@@ -125,13 +125,23 @@ const std::string &CIndexer::getClangResourcesPath() {
 #elif defined(_AIX)
   getClangResourcesPathImplAIX(LibClangPath);
 #else
-  // This silly cast below avoids a C++ warning.
   Dl_info info;
-  if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) == 0)
-llvm_unreachable("Call to dladdr() failed");
+  std::string Path;
+  // This silly cast below avoids a C++ warning.
+  if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) {
+// We now have the CIndex directory, locate clang relative to it.
+LibClangPath += info.dli_fname;
+  } else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, 
nullptr)).empty()) {
+// If we can't get the path using dladdr, try to get the main executable
+// path. This may be needed when we're statically linking libclang with
+// musl libc, for example.
+LibClangPath += Path;
+  } else {
+// It's rather unlikely we end up here. But it could happen, so report an
+// error instead of crashing.
+llvm::report_fatal_error("Could not locate Clang resource path");
+  }
 
-  // We now have the CIndex directory, locate clang relative to it.
-  LibClangPath += info.dli_fname;
 #endif
 
   // Cache our result.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0bd645d - [libclang] Fix error message capitalization

2022-05-29 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2022-05-29T13:42:22+02:00
New Revision: 0bd645d3707dce452663d4634495155321a6fd1c

URL: 
https://github.com/llvm/llvm-project/commit/0bd645d3707dce452663d4634495155321a6fd1c
DIFF: 
https://github.com/llvm/llvm-project/commit/0bd645d3707dce452663d4634495155321a6fd1c.diff

LOG: [libclang] Fix error message capitalization

This was a review suggestion from MaskRay that I forgot to incorporate
in the patch.

See: https://reviews.llvm.org/D124815

Added: 


Modified: 
clang/tools/libclang/CIndexer.cpp

Removed: 




diff  --git a/clang/tools/libclang/CIndexer.cpp 
b/clang/tools/libclang/CIndexer.cpp
index 41f06a83553a..dab3fc4e201d 100644
--- a/clang/tools/libclang/CIndexer.cpp
+++ b/clang/tools/libclang/CIndexer.cpp
@@ -139,7 +139,7 @@ const std::string &CIndexer::getClangResourcesPath() {
   } else {
 // It's rather unlikely we end up here. But it could happen, so report an
 // error instead of crashing.
-llvm::report_fatal_error("Could not locate Clang resource path");
+llvm::report_fatal_error("could not locate Clang resource path");
   }
 
 #endif



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a8efcb9 - [AVR][Clang] Implement __AVR_HAVE_*__ macros

2022-11-22 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2022-11-23T01:21:09+01:00
New Revision: a8efcb96e6db91d1bcc5e56e08814330dbdbfccb

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

LOG: [AVR][Clang] Implement __AVR_HAVE_*__ macros

These macros are defined in avr-gcc and are useful when working with
assembly. For example, startup code needs to copy the contents of .data
from flash to RAM, but should use elpm (instead of lpm) on devices with
more than 64kB flash. Without __AVR_HAVE_ELPM__, there is no way to know
whether the elpm instruction is supported.

This partially fixes https://github.com/llvm/llvm-project/issues/56157.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index e3d1c661df5a3..f2e5d970f3210 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -12,6 +12,7 @@
 
 #include "AVR.h"
 #include "clang/Basic/MacroBuilder.h"
+#include "llvm/ADT/StringSwitch.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -348,6 +349,58 @@ static MCUInfo AVRMcus[] = {
 } // namespace targets
 } // namespace clang
 
+static bool ArchHasELPM(StringRef Arch) {
+  return llvm::StringSwitch(Arch)
+.Cases("31", "51", "6", true)
+.Cases("102", "104", "105", "106", "107", true)
+.Default(false);
+}
+
+static bool ArchHasELPMX(StringRef Arch) {
+  return llvm::StringSwitch(Arch)
+.Cases("51", "6", true)
+.Cases("102", "104", "105", "106", "107", true)
+.Default(false);
+}
+
+static bool ArchHasMOVW(StringRef Arch) {
+  return llvm::StringSwitch(Arch)
+.Cases("25", "35", "4", "5", "51", "6", true)
+.Cases("102", "103", "104", "105", "106", "107", true)
+.Default(false);
+}
+
+static bool ArchHasLPMX(StringRef Arch) {
+  return ArchHasMOVW(Arch); // same architectures
+}
+
+static bool ArchHasMUL(StringRef Arch) {
+  return llvm::StringSwitch(Arch)
+.Cases("4", "5", "51", "6", true)
+.Cases("102", "103", "104", "105", "106", "107", true)
+.Default(false);
+}
+
+static bool ArchHasJMPCALL(StringRef Arch) {
+  return llvm::StringSwitch(Arch)
+.Cases("3", "31", "35", "5", "51", "6", true)
+.Cases("102", "103", "104", "105", "106", "107", true)
+.Default(false);
+}
+
+static bool ArchHas3BytePC(StringRef Arch) {
+  // These devices have more than 128kB of program memory.
+  // Note:
+  //   - Not fully correct for arch 106: only about half the chips have more
+  // than 128kB program memory and therefore a 3 byte PC.
+  //   - Doesn't match GCC entirely: avr-gcc thinks arch 107 goes beyond 128kB
+  // but in fact it doesn't.
+  return llvm::StringSwitch(Arch)
+.Case("6", true)
+.Case("106", true)
+.Default(false);
+}
+
 bool AVRTargetInfo::isValidCPUName(StringRef Name) const {
   return llvm::any_of(
   AVRMcus, [&](const MCUInfo &Info) { return Info.Name == Name; });
@@ -390,6 +443,30 @@ void AVRTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 
   Builder.defineMacro("__AVR_ARCH__", Arch);
 
+  // TODO: perhaps we should use the information from AVRDevices.td instead?
+  if (ArchHasELPM(Arch))
+Builder.defineMacro("__AVR_HAVE_ELPM__");
+  if (ArchHasELPMX(Arch))
+Builder.defineMacro("__AVR_HAVE_ELPMX__");
+  if (ArchHasMOVW(Arch))
+Builder.defineMacro("__AVR_HAVE_MOVW__");
+  if (ArchHasLPMX(Arch))
+Builder.defineMacro("__AVR_HAVE_LPMX__");
+  if (ArchHasMUL(Arch))
+Builder.defineMacro("__AVR_HAVE_MUL__");
+  if (ArchHasJMPCALL(Arch))
+Builder.defineMacro("__AVR_HAVE_JMP_CALL__");
+  if (ArchHas3BytePC(Arch)) {
+// Note: some devices do support eijmp/eicall even though this macro isn't
+// set. This is the case if they have less than 128kB flash and so
+// eijmp/eicall isn't very useful anyway. (This matches gcc, although it's
+// debatable whether we should be bug-compatible in this case).
+Builder.defineMacro("__AVR_HAVE_EIJMP_EICALL__");
+Builder.defineMacro("__AVR_3_BYTE_PC__");
+  } else {
+Builder.defineMacro("__AVR_2_BYTE_PC__");
+  }
+
   if (NumFlashBanks >= 1)
 Builder.defineMacro("__flash", "__attribute__((address_space(1)))");
   if (NumFlashBanks >= 2)

diff  --git a/clang/test/Preprocessor/avr-atmega328p.c 
b/clang/test/Preprocessor/avr-atmega328p.c
index 3ba71445d8cb5..f5f1ef13f151b 100644
--- a/clang/test/Preprocessor/avr-atmega328p.c
+++ b/clang/test/Preprocessor/avr-atmega328p.c
@@ -4,5 +4,9 @@
 // CHECK: #define __AVR 1
 // CHECK: #define __AVR_ARCH__ 5
 // CHECK: #define __AVR_ATmega328P__ 1
+// CHECK-NOT: #define __AVR_HAVE_EIJMP_EICALL__
+// CHECK: #define __AVR_

[clang] 131cddc - [AVR] Fix broken bitcast for aliases in non-zero address space

2022-11-27 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2022-11-27T15:27:42+01:00
New Revision: 131cddcba2c4c953a8a49d7adbf656cab9e9f1c7

URL: 
https://github.com/llvm/llvm-project/commit/131cddcba2c4c953a8a49d7adbf656cab9e9f1c7
DIFF: 
https://github.com/llvm/llvm-project/commit/131cddcba2c4c953a8a49d7adbf656cab9e9f1c7.diff

LOG: [AVR] Fix broken bitcast for aliases in non-zero address space

This was triggered by some code in picolibc. The minimal version looks
like this:

double infinity(void) {
   return 5;
}

extern long double infinityl() __attribute__((__alias__("infinity")));

These two declarations have a different type (not because of the 'long
double', which is also 'double' in IR, but because infinityl has
variadic parameters). This led to a crash in the bitcast which assumed
address space 0.

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/avr/alias-avr.c

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index ae25767bc753a..133c603622f8e 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4002,7 +4002,8 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
 // (If function is requested for a definition, we always need to create a 
new
 // function, not just return a bitcast.)
 if (!IsForDefinition)
-  return llvm::ConstantExpr::getBitCast(Entry, Ty->getPointerTo());
+  return llvm::ConstantExpr::getBitCast(
+  Entry, Ty->getPointerTo(Entry->getAddressSpace()));
   }
 
   // This function doesn't have a complete type (for example, the return

diff  --git a/clang/test/CodeGen/avr/alias-avr.c 
b/clang/test/CodeGen/avr/alias-avr.c
index 88ba3a99eedb2..bcef98a9f5429 100644
--- a/clang/test/CodeGen/avr/alias-avr.c
+++ b/clang/test/CodeGen/avr/alias-avr.c
@@ -6,3 +6,8 @@ int mul(int a, int b) {
 
 // CHECK: @multiply ={{.*}} alias i16 (i16, i16), ptr addrspace(1) @mul
 int multiply(int x, int y) __attribute__((alias("mul")));
+
+// Make sure the correct address space is used when creating an alias that 
needs
+// a pointer cast.
+// CHECK: @smallmul = alias i8 (i16, i16), ptr addrspace(1) @mul
+char smallmul(int a, int b) __attribute__((alias("mul")));



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4add249 - [AVR] Add support for the -mdouble=x flag

2020-03-17 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2020-03-17T13:21:03+01:00
New Revision: 4add24920550beeaed15b24e6427154a58b02e50

URL: 
https://github.com/llvm/llvm-project/commit/4add24920550beeaed15b24e6427154a58b02e50
DIFF: 
https://github.com/llvm/llvm-project/commit/4add24920550beeaed15b24e6427154a58b02e50.diff

LOG: [AVR] Add support for the -mdouble=x flag

This flag is used by avr-gcc (starting with v10) to set the width of the
double type. The double type is by default interpreted as a 32-bit
floating point number in avr-gcc instead of a 64-bit floating point
number as is common on other architectures. Starting with GCC 10, a new
option has been added to control this behavior:
https://gcc.gnu.org/wiki/avr-gcc#Deviations_from_the_Standard

This commit keeps the default double at 32 bits but adds support for the
-mdouble flag (-mdouble=32 and -mdouble=64) to control this behavior.

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

Added: 
clang/test/CodeGen/mdouble.c
clang/test/Driver/mdouble.c

Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Basic/TargetInfo.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 53b87b737568..4ba8c766269c 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -176,6 +176,7 @@ VALUE_LANGOPT(PackStruct  , 32, 0,
 VALUE_LANGOPT(MaxTypeAlign  , 32, 0,
   "default maximum alignment for types")
 VALUE_LANGOPT(AlignDouble, 1, 0, "Controls if doubles should be 
aligned to 8 bytes (x86 only)")
+VALUE_LANGOPT(DoubleSize, 32, 0, "width of double")
 VALUE_LANGOPT(LongDoubleSize, 32, 0, "width of long double")
 LANGOPT(PPCIEEELongDouble, 1, 0, "use IEEE 754 quadruple-precision 
for long double")
 COMPATIBLE_VALUE_LANGOPT(PICLevel, 2, 0, "__PIC__ level")

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bdcd771ff713..3a4830c84483 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2179,6 +2179,8 @@ def mbranches_within_32B_boundaries : Flag<["-"], 
"mbranches-within-32B-boundari
 def mfancy_math_387 : Flag<["-"], "mfancy-math-387">, 
Group;
 def mlong_calls : Flag<["-"], "mlong-calls">, Group,
   HelpText<"Generate branches with extended addressability, usually via 
indirect jumps.">;
+def mdouble_EQ : Joined<["-"], "mdouble=">, Group, Values<"32,64">, 
Flags<[CC1Option]>,
+  HelpText<"Force double to be 32 bits or 64 bits">;
 def LongDouble_Group : OptionGroup<"">, Group,
   DocName<"Long double flags">,
   DocBrief<[{Selects the long double implementation}]>;

diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 58d018c5bd3e..2330339bedfb 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -380,6 +380,20 @@ void TargetInfo::adjust(LangOptions &Opts) {
 LongDoubleFormat = &llvm::APFloat::IEEEquad();
   }
 
+  if (Opts.DoubleSize) {
+if (Opts.DoubleSize == 32) {
+  DoubleWidth = 32;
+  LongDoubleWidth = 32;
+  DoubleFormat = &llvm::APFloat::IEEEsingle();
+  LongDoubleFormat = &llvm::APFloat::IEEEsingle();
+} else if (Opts.DoubleSize == 64) {
+  DoubleWidth = 64;
+  LongDoubleWidth = 64;
+  DoubleFormat = &llvm::APFloat::IEEEdouble();
+  LongDoubleFormat = &llvm::APFloat::IEEEdouble();
+}
+  }
+
   if (Opts.LongDoubleSize) {
 if (Opts.LongDoubleSize == DoubleWidth) {
   LongDoubleWidth = DoubleWidth;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index cb993e75b88c..1193dde5a679 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4580,6 +4580,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   RenderFloatingPointOptions(TC, D, OFastEnabled, Args, CmdArgs,
  JA.getOffloadingDeviceKind());
 
+  if (Arg *A = Args.getLastArg(options::OPT_mdouble_EQ)) {
+if (TC.getArch() == llvm::Triple::avr)
+  A->render(Args, CmdArgs);
+else
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getAsString(Args) << TripleStr;
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_LongDouble_Group)) {
 if (TC.getTriple().isX86())
   A->render(Args, CmdArgs);

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 08a0b9831e0c..e2b24f0cfcea 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2937,6 +2937,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
   Opts.PackStruct