[clang] e09107a - [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-09-17 Thread Raul Tambre via cfe-commits

Author: Raul Tambre
Date: 2020-09-17T19:28:57+03:00
New Revision: e09107ab80dced55414fa458cf78e6cdfe90da6e

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

LOG: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

Instead of relying on whether a certain identifier is a builtin, introduce 
BuiltinAttr to specify a declaration as having builtin semantics.

This fixes incompatible redeclarations of builtins, as reverting the identifier 
as being builtin due to one incompatible redeclaration would have broken rest 
of the builtin calls.
Mostly-compatible redeclarations of builtins also no longer have builtin 
semantics. They don't call the builtin nor inherit their attributes.
A long-standing FIXME regarding builtins inside a namespace enclosed in extern 
"C" not being recognized is also addressed.

Due to the more correct handling attributes for builtin functions are added in 
more places, resulting in more useful warnings.
Tests are updated to reflect that.

Intrinsics without an inline definition in intrin.h had `inline` and `static` 
removed as they had no effect and caused them to no longer be recognized as 
builtins otherwise.

A pthread_create() related test is XFAIL-ed, as it relied on it being 
recognized as a builtin based on its name.
The builtin declaration syntax is too restrictive and doesn't allow custom 
structs, function pointers, etc.
It seems to be the only case and fixing this would require reworking the 
current builtin syntax, so this seems acceptable.

Fixes PR45410.

Reviewed By: rsmith, yutsumi

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

Added: 
clang/test/CodeGen/builtin-redeclaration.c

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/Builtins.def
clang/include/clang/Basic/IdentifierTable.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/Decl.cpp
clang/lib/Headers/intrin.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/AST/ast-dump-attr.cpp
clang/test/CodeGen/callback_pthread_create.c
clang/test/CodeGenCXX/builtins.cpp
clang/test/Sema/implicit-builtin-decl.c
clang/test/Sema/warn-fortify-source.c
clang/test/SemaCXX/cxx11-compat.cpp
clang/test/SemaCXX/warn-unused-local-typedef.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 628649a6998d..c2073e68be2c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3526,3 +3526,11 @@ def ReleaseHandle : InheritableParamAttr {
   let Subjects = SubjectList<[ParmVar]>;
   let Documentation = [ReleaseHandleDocs];
 }
+
+def Builtin : InheritableAttr {
+  let Spellings = [];
+  let Args = [UnsignedArgument<"ID">];
+  let Subjects = SubjectList<[Function]>;
+  let SemaHandler = 0;
+  let Documentation = [Undocumented];
+}

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index fb5b7ec22d07..efefe62c4a2c 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -1020,6 +1020,7 @@ LIBBUILTIN(strncasecmp, "icC*cC*z", "f",   "strings.h", 
ALL_GNU_LANGUAGES)
 LIBBUILTIN(_exit, "vi",   "fr","unistd.h", ALL_GNU_LANGUAGES)
 LIBBUILTIN(vfork, "p","fj","unistd.h", ALL_LANGUAGES)
 // POSIX pthread.h
+// FIXME: Should specify argument types.
 LIBBUILTIN(pthread_create, "",  "fC<2,3>", "pthread.h", ALL_GNU_LANGUAGES)
 
 // POSIX setjmp.h

diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index fc554a35e721..204a0f0cc0a5 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -225,18 +225,6 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   }
   void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; }
 
-  /// True if setNotBuiltin() was called.
-  bool hasRevertedBuiltin() const {
-return ObjCOrBuiltinID == tok::NUM_OBJC_KEYWORDS;
-  }
-
-  /// Revert the identifier to a non-builtin identifier. We do this if
-  /// the name of a known builtin library function is used to declare that
-  /// function, but an unexpected type is specified.
-  void revertBuiltin() {
-setBuiltinID(0);
-  }
-
   /// Return a value indicating whether this is a builtin function.
   ///
   /// 0 is not-built-in. 1+ are specific builtin functions.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 89771046f977..670bd8983265 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4109,6 +4109,8 @@ class Sema final {
 

[clang] a1aa330 - [Sema] Handle objc_super special lookup when checking builtin compatibility

2020-09-18 Thread Raul Tambre via cfe-commits

Author: Raul Tambre
Date: 2020-09-18T20:51:55+03:00
New Revision: a1aa330b202f97ecd243ea9ef0c7ac00a80ea653

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

LOG: [Sema] Handle objc_super special lookup when checking builtin compatibility

objc_super is special and needs LookupPredefedObjCSuperType() called before 
performing builtin type comparisons.
This fixes an error when compiling macOS headers. A test is added.

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

Added: 
clang/test/SemaObjCXX/builtin-objcsuper.mm

Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 20fb5a4d27e7..81d377cebb32 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9671,6 +9671,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 NewFD->addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID));
   } else {
 ASTContext::GetBuiltinTypeError Error;
+LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier());
 QualType BuiltinType = Context.GetBuiltinType(BuiltinID, Error);
 
 if (!Error && !BuiltinType.isNull() &&

diff  --git a/clang/test/SemaObjCXX/builtin-objcsuper.mm 
b/clang/test/SemaObjCXX/builtin-objcsuper.mm
new file mode 100644
index ..a6baf3c5165a
--- /dev/null
+++ b/clang/test/SemaObjCXX/builtin-objcsuper.mm
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -verify %s
+// expected-no-diagnostics
+
+// objc_super has special lookup rules for compatibility with macOS headers, so
+// the following should compile.
+struct objc_super {};
+extern "C" id objc_msgSendSuper(struct objc_super *super, SEL op, ...);
+extern "C" void objc_msgSendSuper_stret(struct objc_super *super, SEL op, ...);



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


[clang] f91f28c - [Sema] Split special builtin type lookups into a separate function

2020-09-21 Thread Raul Tambre via cfe-commits

Author: Raul Tambre
Date: 2020-09-21T19:12:29+03:00
New Revision: f91f28c350df6815d37c521e8f3dc0641a3ca467

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

LOG: [Sema] Split special builtin type lookups into a separate function

In case further such cases appear in the future we've got a generic function to 
add them to.
Additionally changed the ObjC special case to check the language and the 
identifier builtin ID instead of the name.

Addresses the cleanup suggestion from D87917.

Reviewed By: rjmccall

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 12943f2bd5bd..5ca1634d57f9 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3813,6 +3813,7 @@ class Sema final {
   RedeclarationKind Redecl
 = NotForRedeclaration);
   bool LookupBuiltin(LookupResult &R);
+  void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID);
   bool LookupName(LookupResult &R, Scope *S,
   bool AllowBuiltinCreation = false);
   bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 81d377cebb32..2d09138a8b43 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2035,24 +2035,6 @@ Scope *Sema::getNonFieldDeclScope(Scope *S) {
   return S;
 }
 
-/// Looks up the declaration of "struct objc_super" and
-/// saves it for later use in building builtin declaration of
-/// objc_msgSendSuper and objc_msgSendSuper_stret. If no such
-/// pre-existing declaration exists no action takes place.
-static void LookupPredefedObjCSuperType(Sema &ThisSema, Scope *S,
-IdentifierInfo *II) {
-  if (!II->isStr("objc_msgSendSuper"))
-return;
-  ASTContext &Context = ThisSema.Context;
-
-  LookupResult Result(ThisSema, &Context.Idents.get("objc_super"),
-  SourceLocation(), Sema::LookupTagName);
-  ThisSema.LookupName(Result, S);
-  if (Result.getResultKind() == LookupResult::Found)
-if (const TagDecl *TD = Result.getAsSingle())
-  Context.setObjCSuperType(Context.getTagDeclType(TD));
-}
-
 static StringRef getHeaderName(Builtin::Context &BuiltinInfo, unsigned ID,
ASTContext::GetBuiltinTypeError Error) {
   switch (Error) {
@@ -2113,7 +2095,7 @@ FunctionDecl *Sema::CreateBuiltin(IdentifierInfo *II, 
QualType Type,
 NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
  Scope *S, bool ForRedeclaration,
  SourceLocation Loc) {
-  LookupPredefedObjCSuperType(*this, S, II);
+  LookupNecessaryTypesForBuiltin(S, ID);
 
   ASTContext::GetBuiltinTypeError Error;
   QualType R = Context.GetBuiltinType(ID, Error);
@@ -9671,7 +9653,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 NewFD->addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID));
   } else {
 ASTContext::GetBuiltinTypeError Error;
-LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier());
+LookupNecessaryTypesForBuiltin(S, BuiltinID);
 QualType BuiltinType = Context.GetBuiltinType(BuiltinID, Error);
 
 if (!Error && !BuiltinType.isNull() &&
@@ -10880,7 +10862,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 // declaration against the expected type for the builtin.
 if (unsigned BuiltinID = NewFD->getBuiltinID()) {
   ASTContext::GetBuiltinTypeError Error;
-  LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier());
+  LookupNecessaryTypesForBuiltin(S, BuiltinID);
   QualType T = Context.GetBuiltinType(BuiltinID, Error);
   // If the type of the builtin 
diff ers only in its exception
   // specification, that's OK.

diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 7da938cb8c38..cf3ae7ae5d05 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -907,6 +907,24 @@ bool Sema::LookupBuiltin(LookupResult &R) {
   return false;
 }
 
+/// Looks up the declaration of "struct objc_super" and
+/// saves it for later use in building builtin declaration of
+/// objc_msgSendSuper and objc_msgSendSuper_stret.
+static void LookupPredefedObjCSuperType(Sema &Sema, Scope *S) {
+  ASTContext &Context = Sema.Context;
+  LookupResult Result(Sema, &Context.Idents.get("objc_super"), 
SourceLocation(),
+  Sem

[libunwind] 45344cf - [CMake][compiler-rt][libunwind] Compile assembly files as ASM not C, unify workarounds

2020-08-27 Thread Raul Tambre via cfe-commits

Author: Raul Tambre
Date: 2020-08-27T15:40:15+03:00
New Revision: 45344cf7ac5b848f77825ffa37b0cb3b69b9b07b

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

LOG: [CMake][compiler-rt][libunwind] Compile assembly files as ASM not C, unify 
workarounds

It isn't very wise to pass an assembly file to the compiler and tell it to 
compile as a C file and hope that the compiler recognizes it as assembly 
instead.
Simply don't mark the file as C and CMake will recognize the rest.

This was attempted earlier in https://reviews.llvm.org/D85706, but reverted due 
to architecture issues on Apple.
Subsequent digging revealed a similar change was done earlier for libunwind in 
https://reviews.llvm.org/rGb780df052dd2b246a760d00e00f7de9ebdab9d09.
Afterwards workarounds were added for MinGW and Apple:
* https://reviews.llvm.org/rGb780df052dd2b246a760d00e00f7de9ebdab9d09
* https://reviews.llvm.org/rGd4ded05ba851304b26a437896bc3962ef56f62cb

The workarounds in libunwind and compiler-rt are unified and comments added 
pointing to each other.
The workaround is updated to only be used for MinGW for CMake versions before 
3.17, which fixed the issue 
(https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4287).

Additionally fixed Clang not being passed as the assembly compiler for 
compiler-rt runtime build.

Example error:
[525/634] Building C object 
lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o
FAILED: lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o
/opt/tooling/drive/host/bin/clang --target=aarch64-linux-gnu 
-I/opt/tooling/drive/llvm/compiler-rt/lib/tsan/.. -isystem 
/opt/tooling/drive/toolchain/opt/drive/toolchain/include -x c -Wall 
-Wno-unused-parameter -fno-lto -fPIC -fno-builtin -fno-exceptions 
-fomit-frame-pointer -funwind-tables -fno-stack-protector 
-fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only 
-Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -fPIE 
-fno-rtti -Wframe-larger-than=530 -Wglobal-constructors --sysroot=. -MD -MT 
lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o -MF 
lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o.d -o 
lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o -c 
/opt/tooling/drive/llvm/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S
/opt/tooling/drive/llvm/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S:29:1: 
error: expected identifier or '('
.section .text
^
1 error generated.

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

Added: 


Modified: 
clang/runtime/CMakeLists.txt
compiler-rt/cmake/Modules/AddCompilerRT.cmake
libunwind/src/CMakeLists.txt

Removed: 




diff  --git a/clang/runtime/CMakeLists.txt b/clang/runtime/CMakeLists.txt
index e20cc26f60af..61bbbf8faedd 100644
--- a/clang/runtime/CMakeLists.txt
+++ b/clang/runtime/CMakeLists.txt
@@ -75,6 +75,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS 
${COMPILER_RT_SRC_ROOT}/)
 CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
+   -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config

diff  --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index efb660818270..f2f0b5ecde59 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -109,11 +109,11 @@ endfunction()
 
 function(add_asm_sources output)
   set(${output} ${ARGN} PARENT_SCOPE)
-  # Xcode will try to compile asm files as C ('clang -x c'), and that will 
fail.
-  if (${CMAKE_GENERATOR} STREQUAL "Xcode")
-enable_language(ASM)
-  else()
-# Pass ASM file directly to the C++ compiler.
+  # CMake doesn't pass the correct architecture for Apple prior to CMake 3.19. 
https://gitlab.kitware.com/cmake/cmake/-/issues/20771
+  # MinGW didn't work correctly with assembly prior to CMake 3.17. 
https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4287 and 
https://reviews.llvm.org/rGb780df052dd2b246a760d00e00f7de9ebdab9d09
+  # Workaround these two issues by compiling as C.
+  # Same workaround used in libunwind. Also update there if changed here.
+  if((APPLE AND CMAKE_VERSION VERSION_LESS 3.19) OR (MINGW AND CMAKE_VERSION 
VERSION_LESS 3.17))
 set_source_files_properties(${ARGN} PROPERTIES LANGUAGE C)
   endif()
 endfunction()

diff  --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 928bc5992471..094

[clang] 45344cf - [CMake][compiler-rt][libunwind] Compile assembly files as ASM not C, unify workarounds

2020-08-27 Thread Raul Tambre via cfe-commits

Author: Raul Tambre
Date: 2020-08-27T15:40:15+03:00
New Revision: 45344cf7ac5b848f77825ffa37b0cb3b69b9b07b

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

LOG: [CMake][compiler-rt][libunwind] Compile assembly files as ASM not C, unify 
workarounds

It isn't very wise to pass an assembly file to the compiler and tell it to 
compile as a C file and hope that the compiler recognizes it as assembly 
instead.
Simply don't mark the file as C and CMake will recognize the rest.

This was attempted earlier in https://reviews.llvm.org/D85706, but reverted due 
to architecture issues on Apple.
Subsequent digging revealed a similar change was done earlier for libunwind in 
https://reviews.llvm.org/rGb780df052dd2b246a760d00e00f7de9ebdab9d09.
Afterwards workarounds were added for MinGW and Apple:
* https://reviews.llvm.org/rGb780df052dd2b246a760d00e00f7de9ebdab9d09
* https://reviews.llvm.org/rGd4ded05ba851304b26a437896bc3962ef56f62cb

The workarounds in libunwind and compiler-rt are unified and comments added 
pointing to each other.
The workaround is updated to only be used for MinGW for CMake versions before 
3.17, which fixed the issue 
(https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4287).

Additionally fixed Clang not being passed as the assembly compiler for 
compiler-rt runtime build.

Example error:
[525/634] Building C object 
lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o
FAILED: lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o
/opt/tooling/drive/host/bin/clang --target=aarch64-linux-gnu 
-I/opt/tooling/drive/llvm/compiler-rt/lib/tsan/.. -isystem 
/opt/tooling/drive/toolchain/opt/drive/toolchain/include -x c -Wall 
-Wno-unused-parameter -fno-lto -fPIC -fno-builtin -fno-exceptions 
-fomit-frame-pointer -funwind-tables -fno-stack-protector 
-fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only 
-Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -fPIE 
-fno-rtti -Wframe-larger-than=530 -Wglobal-constructors --sysroot=. -MD -MT 
lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o -MF 
lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o.d -o 
lib/tsan/CMakeFiles/clang_rt.tsan-aarch64.dir/rtl/tsan_rtl_aarch64.S.o -c 
/opt/tooling/drive/llvm/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S
/opt/tooling/drive/llvm/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S:29:1: 
error: expected identifier or '('
.section .text
^
1 error generated.

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

Added: 


Modified: 
clang/runtime/CMakeLists.txt
compiler-rt/cmake/Modules/AddCompilerRT.cmake
libunwind/src/CMakeLists.txt

Removed: 




diff  --git a/clang/runtime/CMakeLists.txt b/clang/runtime/CMakeLists.txt
index e20cc26f60af..61bbbf8faedd 100644
--- a/clang/runtime/CMakeLists.txt
+++ b/clang/runtime/CMakeLists.txt
@@ -75,6 +75,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS 
${COMPILER_RT_SRC_ROOT}/)
 CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
+   -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config

diff  --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index efb660818270..f2f0b5ecde59 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -109,11 +109,11 @@ endfunction()
 
 function(add_asm_sources output)
   set(${output} ${ARGN} PARENT_SCOPE)
-  # Xcode will try to compile asm files as C ('clang -x c'), and that will 
fail.
-  if (${CMAKE_GENERATOR} STREQUAL "Xcode")
-enable_language(ASM)
-  else()
-# Pass ASM file directly to the C++ compiler.
+  # CMake doesn't pass the correct architecture for Apple prior to CMake 3.19. 
https://gitlab.kitware.com/cmake/cmake/-/issues/20771
+  # MinGW didn't work correctly with assembly prior to CMake 3.17. 
https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4287 and 
https://reviews.llvm.org/rGb780df052dd2b246a760d00e00f7de9ebdab9d09
+  # Workaround these two issues by compiling as C.
+  # Same workaround used in libunwind. Also update there if changed here.
+  if((APPLE AND CMAKE_VERSION VERSION_LESS 3.19) OR (MINGW AND CMAKE_VERSION 
VERSION_LESS 3.17))
 set_source_files_properties(${ARGN} PROPERTIES LANGUAGE C)
   endif()
 endfunction()

diff  --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 928bc5992471..094

[clang] b5aef90 - [Clang] Fix instantiation of OpaqueValueExprs (Bug #45964)

2021-11-06 Thread Raul Tambre via cfe-commits

Author: Jason Rice
Date: 2021-11-06T10:06:38+02:00
New Revision: b5aef90d4656c5188759d03e2c5c3dc3d8bb398b

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

LOG: [Clang] Fix instantiation of OpaqueValueExprs (Bug #45964)

The structured bindings decomposition of a non-dependent array in a dependent 
context (a template) were, upon instantiation, creating nested OpaqueValueExprs 
that would trigger assertions in CodeGen. Additionally the OpaqueValuesExpr's 
contained SourceExpr is being emitted in CodeGen, but there was no code for its 
transform in template instantiation. This would trigger other assertions such 
as when emitting a DeclRefExpr that refers to a VarDecl that is not marked as 
ODR-used.

This is all based on cursory deduction, but with the way the code flows from 
SemaTemplateInstantiate back to SemaInit, it is apparent that the nesting of 
OpaqueValueExpr is unintentional.

This commit fixes https://bugs.llvm.org/show_bug.cgi?id=45964 and possible 
other issues involving OpaqueValueExprs in template instantiations might be 
resolved.

Reviewed By: aaron.ballman, rjmccall

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

Added: 
clang/test/CodeGenCXX/pr45964-decomp-transform.cpp

Modified: 
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index ad61a6782976e..3f0f21b2e6e73 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -3853,8 +3853,10 @@ ExprResult 
TreeTransform::TransformInitializer(Expr *Init,
   if (auto *FE = dyn_cast(Init))
 Init = FE->getSubExpr();
 
-  if (auto *AIL = dyn_cast(Init))
-Init = AIL->getCommonExpr();
+  if (auto *AIL = dyn_cast(Init)) {
+OpaqueValueExpr *OVE = AIL->getCommonExpr();
+Init = OVE->getSourceExpr();
+  }
 
   if (MaterializeTemporaryExpr *MTE = dyn_cast(Init))
 Init = MTE->getSubExpr();

diff  --git a/clang/test/CodeGenCXX/pr45964-decomp-transform.cpp 
b/clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
new file mode 100644
index 0..927624ca6e370
--- /dev/null
+++ b/clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
+
+int a[1];
+// CHECK: @a = global [1 x i32] zeroinitializer
+template 
+void test_transform() {
+  auto [b] = a;
+}
+void (*d)(){test_transform<0>};
+// CHECK-LABEL: define {{.*}} @_Z14test_transformILi0EEvv
+// CHECK:   [[ENTRY:.*]]:
+// CHECK-NEXT:  [[ARR:%.*]] = alloca [1 x i32]
+// CHECK-NEXT:  [[BEGIN:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* 
[[ARR]], i64 0, i64 0
+// CHECK-NEXT:  br label %[[BODY:.*]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[BODY]]:
+// CHECK-NEXT:  [[CUR:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[NEXT:%.*]], 
%[[BODY]] ]
+// CHECK-NEXT:  [[DEST:%.*]] = getelementptr inbounds i32, i32* [[BEGIN]], i64 
[[CUR]]
+// CHECK-NEXT:  [[SRC:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* @a, 
i64 0, i64 [[CUR]]
+// CHECK-NEXT:  [[X:%.*]] = load i32, i32* [[SRC]]
+// CHECK-NEXT:  store i32 [[X]], i32* [[DEST]]
+// CHECK-NEXT:  [[NEXT]] = add nuw i64 [[CUR]], 1
+// CHECK-NEXT:  [[EQ:%.*]] = icmp eq i64 [[NEXT]], 1
+// CHECK-NEXT:  br i1 [[EQ]], label %[[FIN:.*]], label %[[BODY]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[FIN]]:
+// CHECK-NEXT:  ret void



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


[clang] [Driver] Some adjustments for reloctable linking on OpenBSD (PR #67254)

2023-09-24 Thread Raul Tambre via cfe-commits

tambry wrote:

reloctable→relocatable

Just a fly-by, but IMO the commit message ought to describe the change – "some 
changes" doesn't give much insight.

https://github.com/llvm/llvm-project/pull/67254
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't issue -Wcast-function-type-mismatch for enums with a matching underlying type (PR #87793)

2024-04-05 Thread Raul Tambre via cfe-commits

https://github.com/tambry created 
https://github.com/llvm/llvm-project/pull/87793

Enums are passed as their underlying integral type so they're ABI compatible if 
the size matches.  
Useful with C APIs that pass user-controlled values to callbacks that can be 
made type safe by using enumerations (e.g. GStreamer).

Discovered internally in some code after 
999d4f840777bf8de26d45947192aa0728edc0fb.

>From 21a85320f485e4c11e734c24c6c1d74f8bea215d Mon Sep 17 00:00:00 2001
From: Raul Tambre 
Date: Fri, 5 Apr 2024 18:05:09 +0300
Subject: [PATCH] [clang][Sema] Don't issue -Wcast-function-type-mismatch for
 enums with a matching underlying type

Enums are passed as their underlying integral type so they're ABI compatible if 
the size matches.
Useful with C APIs that pass user-controlled values to callbacks that can be 
made type safe by using enumerations (e.g. GStreamer).
---
 clang/lib/Sema/SemaCast.cpp   | 7 ---
 clang/test/Sema/warn-cast-function-type-strict.c  | 4 
 clang/test/Sema/warn-cast-function-type.c | 4 
 clang/test/SemaCXX/warn-cast-function-type-strict.cpp | 4 
 clang/test/SemaCXX/warn-cast-function-type.cpp| 4 
 5 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 9d85568d97b2d2..b93724a85999be 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -1083,9 +1083,10 @@ static bool argTypeIsABIEquivalent(QualType SrcType, 
QualType DestType,
 return true;
 
   // Allow integral type mismatch if their size are equal.
-  if (SrcType->isIntegralType(Context) && DestType->isIntegralType(Context))
-if (Context.getTypeInfoInChars(SrcType).Width ==
-Context.getTypeInfoInChars(DestType).Width)
+  if ((SrcType->isIntegralType(Context) || SrcType->isEnumeralType()) &&
+  (DestType->isIntegralType(Context) || DestType->isEnumeralType()))
+if (Context.getTypeSizeInChars(SrcType) ==
+Context.getTypeSizeInChars(DestType))
   return true;
 
   return Context.hasSameUnqualifiedType(SrcType, DestType);
diff --git a/clang/test/Sema/warn-cast-function-type-strict.c 
b/clang/test/Sema/warn-cast-function-type-strict.c
index b0a70cf324b711..b21365cdd30a57 100644
--- a/clang/test/Sema/warn-cast-function-type-strict.c
+++ b/clang/test/Sema/warn-cast-function-type-strict.c
@@ -29,8 +29,12 @@ f8 *h;
 f9 *i;
 f10 *j;
 
+enum E : long;
+int efunc(enum E);
+
 void foo(void) {
   a = (f1 *)x;
+  a = (f1 *)efunc; // strict-warning {{cast from 'int (*)(enum E)' to 'f1 *' 
(aka 'int (*)(long)') converts to incompatible function type}}
   b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
   c = (f3 *)x; /* strict-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
   d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
diff --git a/clang/test/Sema/warn-cast-function-type.c 
b/clang/test/Sema/warn-cast-function-type.c
index 09d169026b1c86..969a62043791f4 100644
--- a/clang/test/Sema/warn-cast-function-type.c
+++ b/clang/test/Sema/warn-cast-function-type.c
@@ -19,8 +19,12 @@ f5 *e;
 f6 *f;
 f7 *g;
 
+enum E : long;
+int efunc(enum E);
+
 void foo(void) {
   a = (f1 *)x;
+  a = (f1 *)efunc; // enum is just type system sugar, still passed as a long.
   b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
   c = (f3 *)x;
   d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
diff --git a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp 
b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
index 8887b3c4c5d535..c49b0ac4b26a23 100644
--- a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
@@ -29,8 +29,12 @@ struct S
 
 typedef void (S::*mf)(int);
 
+enum E : long;
+int efunc(E);
+
 void foo() {
   a = (f1 *)x;
+  a = (f1 *)efunc; // strict-warning {{cast from 'int (*)(E)' to 'f1 *' (aka 
'int (*)(long)') converts to incompatible function type}}
   b = (f2 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}}
   b = reinterpret_cast(x); // expected-warning {{cast from 'int 
(*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function 
type}}
   c = (f3 *)x; // strict-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)(...)') converts to incompatible function type}}
diff --git a/clang/test/SemaCXX/warn-cast-function-type.cpp 
b/clang/test/SemaCXX/warn-cast-function-type.cpp
index db2ee030fcbfc9..467fcd6abc2482 100644
--- a/clang/test/SemaCXX/warn-cast-function-type.cpp
+++ b/cla

[clang] [clang][Sema] Don't issue -Wcast-function-type-mismatch for enums with a matching underlying type (PR #87793)

2024-06-03 Thread Raul Tambre via cfe-commits

https://github.com/tambry updated 
https://github.com/llvm/llvm-project/pull/87793

>From 4bc51b03d29b602f75c0ab37f14c932b310871d5 Mon Sep 17 00:00:00 2001
From: Raul Tambre 
Date: Fri, 5 Apr 2024 18:05:09 +0300
Subject: [PATCH] [clang][Sema] Don't issue -Wcast-function-type-mismatch for
 enums with a matching underlying type

Enums are passed as their underlying integral type so they're ABI compatible if 
the size matches.
Useful with C APIs that pass user-controlled values to callbacks that can be 
made type safe by using enumerations (e.g. GStreamer).
---
 clang/lib/Sema/SemaCast.cpp   | 7 ---
 clang/test/Sema/warn-cast-function-type-strict.c  | 9 +
 clang/test/Sema/warn-cast-function-type.c | 9 +
 clang/test/SemaCXX/warn-cast-function-type-strict.cpp | 9 +
 clang/test/SemaCXX/warn-cast-function-type.cpp| 9 +
 5 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 7db6b1dfe923b4..f03dcf05411dfc 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -1093,9 +1093,10 @@ static bool argTypeIsABIEquivalent(QualType SrcType, 
QualType DestType,
 return true;
 
   // Allow integral type mismatch if their size are equal.
-  if (SrcType->isIntegralType(Context) && DestType->isIntegralType(Context))
-if (Context.getTypeInfoInChars(SrcType).Width ==
-Context.getTypeInfoInChars(DestType).Width)
+  if ((SrcType->isIntegralType(Context) || SrcType->isEnumeralType()) &&
+  (DestType->isIntegralType(Context) || DestType->isEnumeralType()))
+if (Context.getTypeSizeInChars(SrcType) ==
+Context.getTypeSizeInChars(DestType))
   return true;
 
   return Context.hasSameUnqualifiedType(SrcType, DestType);
diff --git a/clang/test/Sema/warn-cast-function-type-strict.c 
b/clang/test/Sema/warn-cast-function-type-strict.c
index b0a70cf324b711..c43e0f2fcbc63d 100644
--- a/clang/test/Sema/warn-cast-function-type-strict.c
+++ b/clang/test/Sema/warn-cast-function-type-strict.c
@@ -29,8 +29,17 @@ f8 *h;
 f9 *i;
 f10 *j;
 
+enum E : long;
+int efunc(enum E);
+
+// Produce the underlying `long` type implicitly.
+enum E2 { big = __LONG_MAX__ };
+int e2func(enum E2);
+
 void foo(void) {
   a = (f1 *)x;
+  a = (f1 *)efunc; // strict-warning {{cast from 'int (*)(enum E)' to 'f1 *' 
(aka 'int (*)(long)') converts to incompatible function type}}
+  a = (f1 *)e2func; // strict-warning {{cast from 'int (*)(enum E2)' to 'f1 *' 
(aka 'int (*)(long)') converts to incompatible function type}}
   b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
   c = (f3 *)x; /* strict-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
   d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
diff --git a/clang/test/Sema/warn-cast-function-type.c 
b/clang/test/Sema/warn-cast-function-type.c
index 09d169026b1c86..d474dbf48b8971 100644
--- a/clang/test/Sema/warn-cast-function-type.c
+++ b/clang/test/Sema/warn-cast-function-type.c
@@ -19,8 +19,17 @@ f5 *e;
 f6 *f;
 f7 *g;
 
+enum E : long;
+int efunc(enum E);
+
+// Produce the underlying `long` type implicitly.
+enum E2 { big = __LONG_MAX__ };
+int e2func(enum E2);
+
 void foo(void) {
   a = (f1 *)x;
+  a = (f1 *)efunc; // enum is just type system sugar, still passed as a long.
+  a = (f1 *)e2func; // enum is just type system sugar, still passed as a long.
   b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
   c = (f3 *)x;
   d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
diff --git a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp 
b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
index 8887b3c4c5d535..9203c1aae8c901 100644
--- a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
@@ -29,8 +29,17 @@ struct S
 
 typedef void (S::*mf)(int);
 
+enum E : long;
+int efunc(E);
+
+// Produce the underlying `long` type implicitly.
+enum E2 { big = __LONG_MAX__ };
+int e2func(E2);
+
 void foo() {
   a = (f1 *)x;
+  a = (f1 *)efunc; // strict-warning {{cast from 'int (*)(E)' to 'f1 *' (aka 
'int (*)(long)') converts to incompatible function type}}
+  a = (f1 *)e2func; // strict-warning {{cast from 'int (*)(E2)' to 'f1 *' (aka 
'int (*)(long)') converts to incompatible function type}}
   b = (f2 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}}
   b = reinterpret_cast(x); // expected-warning {{cast from 'int 
(*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to

[clang] [clang][Sema] Don't issue -Wcast-function-type-mismatch for enums with a matching underlying type (PR #87793)

2024-06-03 Thread Raul Tambre via cfe-commits


@@ -19,8 +19,12 @@ f5 *e;
 f6 *f;
 f7 *g;
 
+enum E : long;

tambry wrote:

Good idea, done!

https://github.com/llvm/llvm-project/pull/87793
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't issue -Wcast-function-type-mismatch for enums with a matching underlying type (PR #87793)

2024-06-03 Thread Raul Tambre via cfe-commits

tambry wrote:

I'm able to land myself. 🙂  
Waiting for the CI to go green.

https://github.com/llvm/llvm-project/pull/87793
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't issue -Wcast-function-type-mismatch for enums with a matching underlying type (PR #87793)

2024-06-03 Thread Raul Tambre via cfe-commits

https://github.com/tambry closed https://github.com/llvm/llvm-project/pull/87793
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] 480643a - [CMake] Remove dead code setting policies to NEW

2021-01-19 Thread Raul Tambre via cfe-commits

Author: Raul Tambre
Date: 2021-01-19T17:19:36+02:00
New Revision: 480643a95cd157e654f4f97e8231b18850e7d79a

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

LOG: [CMake] Remove dead code setting policies to NEW

cmake_minimum_required(VERSION) calls cmake_policy(VERSION),
which sets all policies up to VERSION to NEW.
LLVM started requiring CMake 3.13 last year, so we can remove
a bunch of code setting policies prior to 3.13 to NEW as it
no longer has any effect.

Reviewed By: phosek, #libunwind, #libc, #libc_abi, ldionne

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

Added: 


Modified: 
clang/CMakeLists.txt
compiler-rt/CMakeLists.txt
flang/CMakeLists.txt
libcxx/CMakeLists.txt
libcxx/utils/ci/runtimes/CMakeLists.txt
libcxxabi/CMakeLists.txt
libunwind/CMakeLists.txt
lldb/CMakeLists.txt
llvm/CMakeLists.txt
mlir/examples/standalone/CMakeLists.txt

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index f1e5a39cfe05..9e74014134a0 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -1,9 +1,5 @@
 cmake_minimum_required(VERSION 3.13.4)
 
-if(POLICY CMP0075)
-  cmake_policy(SET CMP0075 NEW)
-endif()
-
 # If we are not building as a part of LLVM, build Clang as an
 # standalone project, using LLVM as an external library:
 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )

diff  --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 30302c2c1427..b44ad2c2118e 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -5,10 +5,6 @@
 
 cmake_minimum_required(VERSION 3.13.4)
 
-if(POLICY CMP0075)
-  cmake_policy(SET CMP0075 NEW)
-endif()
-
 # Check if compiler-rt is built as a standalone project.
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR 
COMPILER_RT_STANDALONE_BUILD)
   project(CompilerRT C CXX ASM)

diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 07d34354bd81..79aa53830d5e 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -1,20 +1,6 @@
 cmake_minimum_required(VERSION 3.13.4)
 
-# RPATH settings on macOS do not affect INSTALL_NAME.
-if (POLICY CMP0068)
-  cmake_policy(SET CMP0068 NEW)
-  set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
-endif()
-
-# Include file check macros honor CMAKE_REQUIRED_LIBRARIES.
-if(POLICY CMP0075)
-  cmake_policy(SET CMP0075 NEW)
-endif()
-
-# option() honors normal variables.
-if (POLICY CMP0077)
-  cmake_policy(SET CMP0077 NEW)
-endif()
+set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
 
 option(LINK_WITH_FIR "Link driver with FIR and LLVM" ON)
 option(FLANG_BUILD_NEW_DRIVER "Build the flang compiler driver" OFF)

diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index f4c7e9992f71..46a669500548 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -10,16 +10,7 @@ endif()
 
#===
 cmake_minimum_required(VERSION 3.13.4)
 
-if(POLICY CMP0042)
-  cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
-endif()
-if(POLICY CMP0022)
-  cmake_policy(SET CMP0022 NEW) # Required when interacting with LLVM and Clang
-endif()
-if(POLICY CMP0068)
-  cmake_policy(SET CMP0068 NEW)
-  set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
-endif()
+set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
 
 # Add path for custom modules
 set(CMAKE_MODULE_PATH

diff  --git a/libcxx/utils/ci/runtimes/CMakeLists.txt 
b/libcxx/utils/ci/runtimes/CMakeLists.txt
index 20980b530d4d..ab4182ae949e 100644
--- a/libcxx/utils/ci/runtimes/CMakeLists.txt
+++ b/libcxx/utils/ci/runtimes/CMakeLists.txt
@@ -1,20 +1,8 @@
 cmake_minimum_required(VERSION 3.13.4)
-
-if(POLICY CMP0068)
-  cmake_policy(SET CMP0068 NEW)
-  set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
-endif()
-
-if(POLICY CMP0075)
-  cmake_policy(SET CMP0075 NEW)
-endif()
-
-if(POLICY CMP0077)
-  cmake_policy(SET CMP0077 NEW)
-endif()
-
 project(LLVM_RUNTIMES)
 
+set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
+
 find_package(Python3 COMPONENTS Interpreter)
 if(NOT Python3_Interpreter_FOUND)
   message(WARNING "Python3 not found, using python2 as a fallback")

diff  --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index 146749f57b0a..c8ab9d7acb1d 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -10,10 +10,6 @@ endif()
 
 cmake_minimum_required(VERSION 3.13.4)
 
-if(POLICY CMP0042)
-  cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
-endif()
-
 # Add path for custom modules
 set(CMAKE_MODULE_PATH
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"

diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index e344263173b0..8ae32fbccf4e 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -8,10 +8,6 @@ endif()
 
 cmake_minimum_required(VERSION 3.13.4)
 
-

[clang] 480643a - [CMake] Remove dead code setting policies to NEW

2021-01-19 Thread Raul Tambre via cfe-commits

Author: Raul Tambre
Date: 2021-01-19T17:19:36+02:00
New Revision: 480643a95cd157e654f4f97e8231b18850e7d79a

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

LOG: [CMake] Remove dead code setting policies to NEW

cmake_minimum_required(VERSION) calls cmake_policy(VERSION),
which sets all policies up to VERSION to NEW.
LLVM started requiring CMake 3.13 last year, so we can remove
a bunch of code setting policies prior to 3.13 to NEW as it
no longer has any effect.

Reviewed By: phosek, #libunwind, #libc, #libc_abi, ldionne

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

Added: 


Modified: 
clang/CMakeLists.txt
compiler-rt/CMakeLists.txt
flang/CMakeLists.txt
libcxx/CMakeLists.txt
libcxx/utils/ci/runtimes/CMakeLists.txt
libcxxabi/CMakeLists.txt
libunwind/CMakeLists.txt
lldb/CMakeLists.txt
llvm/CMakeLists.txt
mlir/examples/standalone/CMakeLists.txt

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index f1e5a39cfe05..9e74014134a0 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -1,9 +1,5 @@
 cmake_minimum_required(VERSION 3.13.4)
 
-if(POLICY CMP0075)
-  cmake_policy(SET CMP0075 NEW)
-endif()
-
 # If we are not building as a part of LLVM, build Clang as an
 # standalone project, using LLVM as an external library:
 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )

diff  --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 30302c2c1427..b44ad2c2118e 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -5,10 +5,6 @@
 
 cmake_minimum_required(VERSION 3.13.4)
 
-if(POLICY CMP0075)
-  cmake_policy(SET CMP0075 NEW)
-endif()
-
 # Check if compiler-rt is built as a standalone project.
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR 
COMPILER_RT_STANDALONE_BUILD)
   project(CompilerRT C CXX ASM)

diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 07d34354bd81..79aa53830d5e 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -1,20 +1,6 @@
 cmake_minimum_required(VERSION 3.13.4)
 
-# RPATH settings on macOS do not affect INSTALL_NAME.
-if (POLICY CMP0068)
-  cmake_policy(SET CMP0068 NEW)
-  set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
-endif()
-
-# Include file check macros honor CMAKE_REQUIRED_LIBRARIES.
-if(POLICY CMP0075)
-  cmake_policy(SET CMP0075 NEW)
-endif()
-
-# option() honors normal variables.
-if (POLICY CMP0077)
-  cmake_policy(SET CMP0077 NEW)
-endif()
+set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
 
 option(LINK_WITH_FIR "Link driver with FIR and LLVM" ON)
 option(FLANG_BUILD_NEW_DRIVER "Build the flang compiler driver" OFF)

diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index f4c7e9992f71..46a669500548 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -10,16 +10,7 @@ endif()
 
#===
 cmake_minimum_required(VERSION 3.13.4)
 
-if(POLICY CMP0042)
-  cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
-endif()
-if(POLICY CMP0022)
-  cmake_policy(SET CMP0022 NEW) # Required when interacting with LLVM and Clang
-endif()
-if(POLICY CMP0068)
-  cmake_policy(SET CMP0068 NEW)
-  set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
-endif()
+set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
 
 # Add path for custom modules
 set(CMAKE_MODULE_PATH

diff  --git a/libcxx/utils/ci/runtimes/CMakeLists.txt 
b/libcxx/utils/ci/runtimes/CMakeLists.txt
index 20980b530d4d..ab4182ae949e 100644
--- a/libcxx/utils/ci/runtimes/CMakeLists.txt
+++ b/libcxx/utils/ci/runtimes/CMakeLists.txt
@@ -1,20 +1,8 @@
 cmake_minimum_required(VERSION 3.13.4)
-
-if(POLICY CMP0068)
-  cmake_policy(SET CMP0068 NEW)
-  set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
-endif()
-
-if(POLICY CMP0075)
-  cmake_policy(SET CMP0075 NEW)
-endif()
-
-if(POLICY CMP0077)
-  cmake_policy(SET CMP0077 NEW)
-endif()
-
 project(LLVM_RUNTIMES)
 
+set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
+
 find_package(Python3 COMPONENTS Interpreter)
 if(NOT Python3_Interpreter_FOUND)
   message(WARNING "Python3 not found, using python2 as a fallback")

diff  --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index 146749f57b0a..c8ab9d7acb1d 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -10,10 +10,6 @@ endif()
 
 cmake_minimum_required(VERSION 3.13.4)
 
-if(POLICY CMP0042)
-  cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
-endif()
-
 # Add path for custom modules
 set(CMAKE_MODULE_PATH
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"

diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index e344263173b0..8ae32fbccf4e 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -8,10 +8,6 @@ endif()
 
 cmake_minimum_required(VERSION 3.13.4)
 
-