Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

130 lines
5.9 KiB
C++

// RUN: %check_clang_tidy %s abseil-time-comparison %t -- -- -I%S/Inputs
#include "absl/time/time.h"
void f() {
double x;
absl::Duration d1, d2;
bool b;
absl::Time t1, t2;
// Check against the RHS
b = x > absl::ToUnixSeconds(t1);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = absl::FromUnixSeconds(x) > t1;
b = x >= absl::ToUnixSeconds(t1);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = absl::FromUnixSeconds(x) >= t1;
b = x == absl::ToUnixSeconds(t1);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = absl::FromUnixSeconds(x) == t1;
b = x <= absl::ToUnixSeconds(t1);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = absl::FromUnixSeconds(x) <= t1;
b = x < absl::ToUnixSeconds(t1);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = absl::FromUnixSeconds(x) < t1;
b = x == absl::ToUnixSeconds(t1 - d2);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = absl::FromUnixSeconds(x) == t1 - d2;
b = absl::ToUnixSeconds(t1) > absl::ToUnixSeconds(t2);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = t1 > t2;
// Check against the LHS
b = absl::ToUnixSeconds(t1) < x;
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = t1 < absl::FromUnixSeconds(x);
b = absl::ToUnixSeconds(t1) <= x;
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = t1 <= absl::FromUnixSeconds(x);
b = absl::ToUnixSeconds(t1) == x;
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = t1 == absl::FromUnixSeconds(x);
b = absl::ToUnixSeconds(t1) >= x;
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = t1 >= absl::FromUnixSeconds(x);
b = absl::ToUnixSeconds(t1) > x;
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = t1 > absl::FromUnixSeconds(x);
// Comparison against zero
b = absl::ToUnixSeconds(t1) < 0.0;
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = t1 < absl::UnixEpoch();
b = absl::ToUnixSeconds(t1) < 0;
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = t1 < absl::UnixEpoch();
// Scales other than Seconds
b = x > absl::ToUnixMicros(t1);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = absl::FromUnixMicros(x) > t1;
b = x >= absl::ToUnixMillis(t1);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = absl::FromUnixMillis(x) >= t1;
b = x == absl::ToUnixNanos(t1);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = absl::FromUnixNanos(x) == t1;
b = x <= absl::ToUnixMinutes(t1);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = absl::FromUnixMinutes(x) <= t1;
b = x < absl::ToUnixHours(t1);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = absl::FromUnixHours(x) < t1;
// A long expression
bool some_condition;
int very_very_very_very_long_variable_name;
absl::Time SomeTime;
if (some_condition && very_very_very_very_long_variable_name
< absl::ToUnixSeconds(SomeTime)) {
// CHECK-MESSAGES: [[@LINE-2]]:25: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: if (some_condition && absl::FromUnixSeconds(very_very_very_very_long_variable_name) < SomeTime) {
return;
}
// A complex expression
int y;
b = (y + 5) * 10 > absl::ToUnixMillis(t1);
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: b = absl::FromUnixMillis((y + 5) * 10) > t1;
// We should still transform the expression inside this macro invocation
#define VALUE_IF(v, e) v ? (e) : 0
int a = VALUE_IF(1, 5 > absl::ToUnixSeconds(t1));
// CHECK-MESSAGES: [[@LINE-1]]:23: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: int a = VALUE_IF(1, absl::FromUnixSeconds(5) > t1);
#undef VALUE_IF
#define VALUE_IF_2(e) (e)
#define VALUE_IF(v, e) v ? VALUE_IF_2(e) : VALUE_IF_2(0)
int a2 = VALUE_IF(1, 5 > absl::ToUnixSeconds(t1));
// CHECK-MESSAGES: [[@LINE-1]]:24: warning: perform comparison in the time domain [abseil-time-comparison]
// CHECK-FIXES: int a2 = VALUE_IF(1, absl::FromUnixSeconds(5) > t1);
#undef VALUE_IF
#undef VALUE_IF_2
#define VALUE_IF_2(e) (e)
#define VALUE_IF(v, e, type) (v ? VALUE_IF_2(absl::To##type##Seconds(e)) : 0)
int a3 = VALUE_IF(1, t1, Unix);
#undef VALUE_IF
#undef VALUE_IF_2
#define VALUE_IF_2(e) (e)
#define VALUE_IF(v, e, type) (v ? (5 > VALUE_IF_2(absl::To##type##Seconds(e))) : 0)
int a4 = VALUE_IF(1, t1, Unix);
#undef VALUE_IF
#undef VALUE_IF_2
// These should not match
b = 6 < 4;
#define TODOUBLE(x) absl::ToUnixSeconds(x)
b = 5.0 > TODOUBLE(t1);
#undef TODOUBLE
#define THIRTY 30.0
b = THIRTY > absl::ToUnixSeconds(t1);
#undef THIRTY
}