[libc-commits] [libc] [libc] Fix `nanosleep` definition in the posix spec (PR #67855)

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Fri Sep 29 14:22:31 PDT 2023


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/67855

Summary:
The POSIX standard expects the first argument to this function to be
constant, e.g. https://man7.org/linux/man-pages/man2/nanosleep.2.html.
This fixes that problem and also corrects an obvious problem with
enabling this for offloading.


>From dc61d147265b036c7b439ebff80c4319e5330100 Mon Sep 17 00:00:00 2001
From: Joseph Huber <jhuber6 at vols.utk.edu>
Date: Fri, 29 Sep 2023 16:20:40 -0500
Subject: [PATCH] [libc] Fix `nanosleep` definition in the posix spec

Summary:
The POSIX standard expects the first argument to this function to be
constant, e.g. https://man7.org/linux/man-pages/man2/nanosleep.2.html.
This fixes that problem and also corrects an obvious problem with
enabling this for offloading.
---
 clang/lib/Headers/llvm_libc_wrappers/time.h | 2 +-
 libc/spec/posix.td                          | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/llvm_libc_wrappers/time.h b/clang/lib/Headers/llvm_libc_wrappers/time.h
index 894f6f6c7aaf774..9d1340c4eb748f0 100644
--- a/clang/lib/Headers/llvm_libc_wrappers/time.h
+++ b/clang/lib/Headers/llvm_libc_wrappers/time.h
@@ -25,7 +25,7 @@
 
 _Static_assert(sizeof(clock_t) == sizeof(long), "ABI mismatch!");
 
-#include <llvm-libc-decls/ctype.h>
+#include <llvm-libc-decls/time.h>
 
 #pragma omp end declare target
 
diff --git a/libc/spec/posix.td b/libc/spec/posix.td
index d09c7228549dfc7..a367cf2a6935c02 100644
--- a/libc/spec/posix.td
+++ b/libc/spec/posix.td
@@ -44,6 +44,7 @@ def ConstStructDirentPtrPtr : ConstType<StructDirentPtrPtr>;
 
 def StructTimeSpec : NamedType<"struct timespec">;
 def StructTimeSpecPtr : PtrType<StructTimeSpec>;
+def ConstStructTimeSpecPtr : ConstType<StructTimeSpecPtr>;
 
 def StructSchedParam : NamedType<"struct sched_param">;
 def StructSchedParamPtr : PtrType<StructSchedParam>;
@@ -1192,7 +1193,7 @@ def POSIX : StandardSpec<"POSIX"> {
           FunctionSpec<
               "nanosleep",
               RetValSpec<IntType>,
-              [ArgSpec<StructTimeSpecPtr>, ArgSpec<StructTimeSpecPtr>]
+              [ArgSpec<ConstStructTimeSpecPtr>, ArgSpec<StructTimeSpecPtr>]
           >,
       ]
   >;



More information about the libc-commits mailing list