Issue 107547
Summary [llvm] [SimplifyCFG]
Labels new issue
Assignees
Reporter dongjianqiang2
    system_status.h
`
#ifndef SYSTEM_STATUS_H
#define SYSTEM_STATUS_H

#include <stdint.h>

#define SUCCESS 0
#define FAILURE 1

#define MAX_SYSTEM_UNITS (15)

typedef uint8_t flag_t;

typedef struct {
    int status_health;
    int status_active;
} system_status_t;

typedef uint32_t unit_id_t;

typedef struct tagSYSTEM_UNIT {
    uint32_t category;
    unit_id_t unitId;
 int status_health;
    int status_active;
    char unitName[32];
} SYSTEM_UNIT;

typedef struct tagSYSTEM_COLLECTION {
    uint32_t unitCount;
    SYSTEM_UNIT unitArray[MAX_SYSTEM_UNITS];
} SYSTEM_COLLECTION;

// Function declaration for updateSystemStatus
int32_t updateSystemStatus(uint32_t collectionId);

// Declarations for external dependencies
SYSTEM_COLLECTION* getCollectionById(uint32_t collectionId);
void processUnit(unit_id_t unitId, system_status_t* status);
uint32_t getActiveStateAlert(uint32_t activeState);
`
system_status.c
`
#include "system_status.h"
#include <stdio.h>

// Definition of updateSystemStatus function
int32_t updateSystemStatus(uint32_t collectionId)
{
    uint32_t i;
    system_status_t systemStatus[MAX_SYSTEM_UNITS];
    unit_id_t unitArray[MAX_SYSTEM_UNITS] = { 0 };
    uint32_t unitCount;
    SYSTEM_COLLECTION* collectionInfo = NULL;

    collectionInfo = getCollectionById(collectionId);
 if (collectionInfo == NULL) {
        return FAILURE;
    }

 unitCount = collectionInfo->unitCount;
    for (i = 0; i < unitCount; i++) {
        unitArray[i] = collectionInfo->unitArray[i].unitId;
 }

    for (i = 0; i < unitCount; i++) {
 processUnit(unitArray[i], &systemStatus[i]);
    }

    return getActiveStateAlert(systemStatus[0].status_active);
}
`
main.c
`
#include "system_status.h"
#include <stdio.h>
#include <string.h>

// Mock function to return system collection information by ID
SYSTEM_COLLECTION* getCollectionById(uint32_t collectionId)
{
 static SYSTEM_COLLECTION systemCollection;
    systemCollection.unitCount = 0;
    return &systemCollection;
}

// Mock function to process each unit and update its status
void processUnit(unit_id_t unitId, system_status_t* status)
{
    printf("Processing unit with ID: %u\n", unitId);
    status->status_health = 100 - (unitId * 10);
 status->status_active = (unitId % 2);
}

// Mock function to check system active status crisis
uint32_t getActiveStateAlert(uint32_t activeState)
{
    if (activeState == 0) {
        printf("Alert: The system is not active!\n");
        return FAILURE;
    } else {
        printf("System is running normally.\n");
        return SUCCESS;
    }
}

// Main function to demonstrate the use of updateSystemStatus
int main()
{
    uint32_t collectionId = 1;
 int32_t result = updateSystemStatus(collectionId);

    if (result == SUCCESS) {
        printf("System status updated successfully.\n");
 } else {
        printf("Failed to update system status.\n");
 }

    return 0;
}
`
clang system_status.c main.c -O2 -fno-tree-vectorize
./a.out
`Segmentation fault (core dumped)`
gcc system_status.c main.c -O2 -fno-tree-vectorize
./a.out
`System is running normally.
System status updated successfully.
`
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to